Previously on my blog I described a workaround in passing data to JSF bean method.

It's very useful when you need some simple transformation with data which you are going to display on a page or compare with something using EL.

But now I've already found and tested the best way to do it. This way is a creation of the custom EL function which performs your transformation. This solution is very elegant but it's now new. I found a lot of posts on the Internet dated 2006-... about this topic. But I just want to show you my solution and tell you what didn't work for me.

My environment consists of Jboss 5.1 + Facelets 1.1.15-B1 + JSF 1.2.

I have a tag library based on facelets in my project. It was done accordingly to

So at first I want to tell you what didn't work:

  • using of function declaration in my taglib.xml like it's shown below didn't get me any results





               <function-signature>boolean isInteger(java.lang.String)</function-signature>



  • I had to create a separated library for functions because when I tried to define my custom tags in the same file as library-class it didn't work either.

Now about how it works.

1) Declaring library in web.xml





2) I created taglib file (test.functions.taglib.xml):

<?xml version="1.0"?>

<!DOCTYPE facelet-taglib PUBLIC

  "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN"





3) I created


import java.lang.reflect.Method;

import java.lang.reflect.Modifier;



import com.sun.facelets.tag.AbstractTagLibrary;



public final class FnLibrary extends AbstractTagLibrary {


          public final static String NAMESPACE = "";



          public static final FnLibrary INSTANCE = new FnLibrary();



          public FnLibrary() {


                    try {

                              Method[] methods = FunctionsLibrary.class.getMethods();

                              for (int i = 0; i < methods.length; i++) {

                                        if (Modifier.isStatic(methods[i].getModifiers())) {

                                                  this.addFunction(methods[i].getName(), methods[i]);



                    } catch (Exception e) {

                              throw new RuntimeException(e);






4) And I created


public class FunctionsLibrary {


          public static boolean isInteger(String value) {

                    if (value != null) {

                              try {


                                        return true;

                              } catch (NumberFormatException e) {




                    return false;




For using this library you just need to define prefix in your root element xmlns:tf="" and then you can use it in EL expressions.

So #{tf:isInteger('345')} returns true. =)


P.S. I used the following link for my final solution. It's completely based on this source. I'm just wondering why other solutions didn't work.