I'm trying to use Apache Commons Lang 3 in my JSF 2 application, and I followed BalusC's example
But when I included this line in my .xhtml page :
<%@taglib prefix="f" uri="/WEB-INF/functions.tld" %>
I have an error while parsing the page code.
How can I fix the problem?
The answer was targeted on a question whose asker is known to use JSF 1.x on JSP. The syntax which you've there is specific to JSP, the legacy predecesor of Facelets which is deprecated since JSF 2.0.
Get rid of the
functions.tld
file altogether. The proper JSF 2.x Facelets way of declaring a custom function based on an existing static method is as follows:First create a
/WEB-INF/functions.taglib.xml
:Then register it in
/WEB-INF/web.xml
:(that step is unnecessary when it is placed in
/META-INF
of a JAR file which is in turn placed in/WEB-INF/lib
)Finally declare and use it as follows:
Note that I've updated the answer you found accordingly. Also note that this function is already provided out the box as
#{of:escapeJS(bean.foo)}
by JSF utility library OmniFaces, in case you're using it.