Facelets String Functions

A string concatenation function for Facelets

JSF is really great, but there are a few things missing straight out of the box. One thing that becomes readily apparent is the lack of string functions in JSF EL. It's easy to remedy with some Facelets functions.

String concatenation

Function declaration in .taglib.xml file:

<function>
   <function-name>concat</function-name>
   <function-class>eg.FaceletsFunctions</function-class>
   <function-signature>java.lang.String concat(java.lang.String,java.lang.String)</function-signature>
</function>

Java code:

    public static String concat(String a,String b)
    {
        return StringUtils.join(new String[]{a,b},null);
    }
  • Note: This implementation uses StringUtils from commons-lang.
  • Also note: As of this writing, Facelets doesn't know how to bind to functions that use Java5 ellipsis.

Usage:

    <a href="#{mytags:concat('/xyz.jsp',(!empty someParam) ? mytags:concat('&theParam=',someParam) : '')}">click here</a>

Labels

jsf jsf Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.