jsf - Programmatically register taglib reference -
is there way programmatically, in java code, register custom taglib reference?
using jsf 1.2_09, rich faces 3.3.3, jsf-facelets 1.1.14.
specifically:
in code, jsf expression language used job us, concatenation of 2 results in 1 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); (int = 0; < jsfdisplayvalue.size(); i++){ object value = ef.createvalueexpression(elcontext, jsfdisplayvalue.get(i), object.class).getvalue(ctx.getelcontext()); //do value... }
e.g., elements of jsfdisplayvalue
can be:
"#{row.name} #{row.surname}", "#{row.age}", "#{tagfoo:foofunction(row.age)}"
...
problem occurs when expression contains function, highlighted, tagfoo:foofunction
.
stack trace:
javax.el.elexception: function 'tagfoo:foofunction' not found @ org.apache.el.lang.expressionbuilder.visit(expressionbuilder.java:198) @ org.apache.el.parser.simplenode.accept(simplenode.java:147) @ org.apache.el.lang.expressionbuilder.prepare(expressionbuilder.java:155) @ org.apache.el.lang.expressionbuilder.build(expressionbuilder.java:173) @ org.apache.el.lang.expressionbuilder.createvalueexpression(expressionbuilder.java:217) @ org.apache.el.expressionfactoryimpl.createvalueexpression(expressionfactoryimpl.java:67)
elcontext doesn't recognize custom function, , can't resolve function because tagfoo
unknown elcontext. how can register taglib reference in java class, elcontext can recognise custom functions?
on jsf page, this:
<jsp:root version="2.0" xmlns:jsp="http://java.sun.com/jsp/page" xmlns:tagfoo="http://tagfoo.org/tags">
p.s.
custom functions working on jsf pages.
i'm sorry i'm bit late, stumbled upon same problem today.
inspecting elcontext , functionmapper instances, have seen custom implementations of standard abstract class.
as want keep code portable, decided not involved writing code specific implementation, , abstract class defines read contract , omits write side of things, wrote custom functionmapper. here meaningfull code:
public void register(string prefix, string function, method method) { register.put(prefix + ":" + function, method); } @override public method resolvefunction(string prefix, string localname) { if (register.containskey(prefix + ":" + localname)) { return register.get(prefix + ":" + localname); } (functionmapper : delegates) { final method current = it.resolvefunction(prefix, localname); if (current != null) { return current; } } return null; }
by wrapping standard functionmapper, can add own functions , keep standard environment ok. in case, had write custom elcontext implementation too, basicaly clones default elcontext , wraps functionmapper.
i'm pretty happy results, hope helps.