Help

Built with Seam

You can find the full source code for this website in the Seam package in the directory /examples/wiki. It is licensed under the LGPL.

FAQ Category:

You want chop the last character from a string in EL? Jakarta Commons Lang's StringUtils has a chop() method. There are many other String operations available if you integrate it with your Facelets templates.

You can turn this - and any static method really - into a JSF function with a custom tag lib, e.g. META-INF/custom.taglib.xml:

<?xml version="1.0"?>
<!DOCTYPE facelet-taglib PUBLIC "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN" "facelet-taglib_1_0.dtd">
<facelet-taglib>
 <namespace>http://org.apache.commons.lang/StringUtils</namespace>
 <function>
  <function-name>chop</function-name>
  <function-class>org.apache.commons.lang.StringUtils</function-class>
  <function-signature>java.lang.String chop(java.lang.String)</function-signature>
 </function>
</facelet-taglib>

You may need to alter your build.xml to ensure the custom.taglib.xml finds its way to your WAR's META-INF folder.

And use it as such:

value="#{stringutils:chop(keyword)}"

Be sure to bind the stringutils prefix to http://org.apache.commons.lang/StringUtils - add this xmlns attribute to the root element of the page:

xmlns:stringutils="http://org.apache.commons.lang/StringUtils"

(from James Kelly)

2 comments:
 
08. Jul 2008, 20:04 America/New_York | Link
Paulo Angelo | reddhatt.AT.gmail.com

Very intersting, but I could not make it run. :)

Does anyone knows a running example?

Thank you,

PA

 
08. Aug 2009, 00:29 America/New_York | Link

It's a lot simpler if you just define the class as a stateless Seam component.

<component name="stringUtils" class="org.apache.commons.lang.StringUtils" scope="stateless"/>

Then you can just invoke its methods directly in EL. JBoss EL can invoke static methods.

value="#{stringUtils.chop(keyword)}"

This is a lot easier than having to setup Facelets functions and there is no weird syntax.

 

Dan Allen | mojavelinux.com | Author of Seam in Action