• cdi
  • components
  • contexts
  • converters
  • eventlisteners
  • exceptionhandlers
  • facesviews
  • filters
  • functions
  • managedbeans
  • push
  • resourcehandlers
  • scripts
  • servlets
  • taghandlers
  • utils
  • validators
  • viewhandlers
-
  • Arrays
  • Converters
  • Dates
  • Numbers
  • Objects
  • Request
  • Strings

Collection of EL functions for string manipulation: of:abbreviate(), of:capitalize(), of:concat(), of:prettyURL(), of:encodeURL(), of:escapeJS() and of:formatX().

Instead of of:formatX(), you can also use <o:outputFormat>.

Feature request

If you know more useful methods/functions which you think should be added to this OmniFaces utility class so that everyone can benefit from a "standard" JSF utility library, feel free to post a feature request.

Demo

Abbreviate a long string: Lorem ipsum dolor si...

Capitalize a string: Left

Concat 2 strings: leftright

Regex-replace a string: ”Lorem” ”ipsum” ”dolor” ”sit” ”amet”, ”consectetur” ”adipiscing” ”elit”.

Regex-match a string: true

Following functions deal with the following string: "STRING with díãçrïtìcs"

  • Create a pretty URL (part): string-with-diacritics check link URL (don't click :) )
  • URL-encode with UTF-8: STRING+with+d%C3%AD%C3%A3%C3%A7r%C3%AFt%C3%ACcs click link
  • Escape for usage in JavaScript: STRING with d\u00ed\u00e3\u00e7r\u00eft\u00eccs click to see alert

Format strings in EL:

  • one two
  • one two three four
  • one two three four five six
  • one two three four five six seven eight
  • one two three four five six seven eight nine ten
Demo source code
<c:set var="string1" value="Lorem ipsum dolor sit amet, consectetur adipiscing elit." />
<c:set var="string2" value="left" />
<c:set var="string3" value="right" />
<c:set var="string4" value="STRING with díãçrïtìcs" />

<p>
    Abbreviate a long string: #{of:abbreviate(string1, 20)}
</p>
<p>
    Capitalize a string: #{of:capitalize(string2)}
</p>
<p>
    Concat 2 strings: #{of:concat(string2, string3)}
</p>
<p>
    Regex-replace a string: #{of:replaceAll(string1, '\\b', '&#x201D;')}
</p>
<p>
    Regex-match a string: #{of:matches(string2, '\\p{IsLatin}+')}
</p>

<p>
    Following functions deal with the following string: "#{string4}"
</p>
<ul>
    <li>
        Create a pretty URL (part): #{of:prettyURL(string4)} 
        <a href="#{of:prettyURL(string4)}">check link URL</a> (don't click :) )
    </li>
    <li>
        URL-encode with UTF-8: #{of:encodeURL(string4)} 
        <a href="#{request.requestURI}?test=#{of:encodeURL(string4)}">click link</a>
    </li>
    <li>
        Escape for usage in JavaScript: #{of:escapeJS(string4)} 
        <a href="javascript:alert('#{of:escapeJS(string4)}')">click to see alert</a>
    </li>
</ul>

<p>
    Format strings in EL:
</p>
<ul>
    <li>#{of:format1('one {0}', 'two')}</li>
    <li>#{of:format2('one {0} three {1}', 'two', 'four')}</li>
    <li>#{of:format3('one {0} three {1} five {2}', 'two', 'four', 'six')}</li>
    <li>#{of:format4('one {0} three {1} five {2} seven {3}', 'two', 'four', 'six', 'eight')}</li>
    <li>#{of:format5('one {0} three {1} five {2} seven {3} nine {4}', 'two', 'four', 'six', 'eight', 'ten')}</li>
</ul>