Sep 13, 2018

String functions in JSF EL (JSF Expression Language)

Add JSTL functions namespace in Facelets XHTML:

xmlns:fn="http://java.sun.com/jsp/jstl/functions"

Example1:

#{fn:startsWith(beanName.fieldName,'PREFIX_')}

Example 2:
<c:forEach items="${contacts}" var="contact">
   <c:if test="${not fn:containsIgnoreCase(contact, 'i88.ca')}">       <p>Doesn't contain 'i88.ca'</p> 
   </c:if> 
</c:forEach>
Other functions:
  • toUpperCase, toLowerCase: Changes the capitalization of a string
  • substring, substringBefore, substringAfter: Gets a subset of a string
  • trim: Trims white space from a string
  • replace: Replaces characters in a string
  • indexOf, startsWith, endsWith, contains, containsIgnoreCase: Checks whether a string contains another string
  • split: Splits a string into an array
  • join: Joins a collection into a string
  • escapeXml: Escapes XML characters in a string
  • length: Returns the number of items in a collection, or the number of characters in a string
See also:
http://docs.oracle.com/cd/E17802_01/products/products/jsp/jstl/1.1/docs/tlddocs/fn/tld-summary.html