Is there a way to programmatically, in a java code, register custom taglib reference?
I am using JSF 1.2_09, rich faces 3.3.3, jsf-facelets 1.1.14.
Specifically:
In this code, jsf Expression Language is used to do some job for us, like concatenation of 2 results in one field or similar stuff..
FacesContext ctx = FacesContext.getCurrentInstance();
Application app = ctx.getApplication();
ExpressionFactory ef = app.getExpressionFactory();
ELContext elContext = ctx.getELContext();
ValueExpression valueExpression = new OverrideValueExpression(singleResult.getClass(), singleResult);
elContext.getVariableMapper().setVariable("row", valueExpression);
for (int i = 0; i < jsfDisplayValue.size(); i++){
Object value = ef.createValueExpression(elContext, jsfDisplayValue.get(i), Object.class).getValue(ctx.getELContext());
//Do something with value...
}
E.g., elements of jsfDisplayValue
can be:
"#{row.name} #{row.surname}", "#{row.age}", "#{tagfoo:fooFunction(row.age)}"
...
The problem occurs when expression contains a function, like highlighted, tagfoo:fooFunction
.
Stack trace:
javax.el.ELException: Function 'tagfoo:fooFunction' not found
at org.apache.el.lang.ExpressionBuilder.visit(ExpressionBuilder.java:198)
at org.apache.el.parser.SimpleNode.accept(SimpleNode.java:147)
at org.apache.el.lang.ExpressionBuilder.prepare(ExpressionBuilder.java:155)
at org.apache.el.lang.ExpressionBuilder.build(ExpressionBuilder.java:173)
at org.apache.el.lang.ExpressionBuilder.createValueExpression(ExpressionBuilder.java:217)
at org.apache.el.ExpressionFactoryImpl.createValueExpression(ExpressionFactoryImpl.java:67)
ELContext doesn't recognize custom function, and it can't resolve the function because tagfoo
is unknown to ELContext.
How can I register taglib reference in java class, so ELContext can recognise custom functions?
On a JSF page, I would do this:
<jsp:root version="2.0" xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:tagfoo="http://tagfoo.org/tags">
P.S.
My custom functions are working properly on jsf pages.