|
JSF, although a powerful framework does not have many tools to
assist in the development of composite controls. Whether building a
control that has a few controls in it or a control comprised of 100s of
children, there is no easy solution. The JSF specification was more
written to build components that render themselves entirely.
With that said Facelets
is a great add on to JSF and has some great templating features. Using
a user tag (a.k.a. source tag), a composite control can be easily
created. The trouble is that it is not possible out-of-the-box to pass
method bindings to children components.
For example:
Snippet from taglib.xml:
<tag> <tag-name>test</tag-name> <source>tags/testTag.xhtml</source> </tag>
Usage in an XHTML file:
<my:test actionListener="#{myBean.doSomething}" />
User Tag file:
<ui:composition> <h:commandButton value="Click Me" actionListener="#{actionListener}" /> </ui:composition>
The problem with the above code is that the user tag handler of
facelets always creates ValueExpression objects for each attribute in
the source tag. This is fine for properties, but in the above case, a
MethodExpression is what "ought" to be created.
I wanted to solve this problem, but in such a way to avoid people
having to create new tag handlers or component handlers. I wanted a
re-usable complete solution. After dragging myself through the mire of
source code, I found what I needed in the facelets API to extend it. My
solution is two part:
- Create a tag handler with component support
- Create a new value expression that returns method expressions
Creating a value expression that is a method expression
http://andrewfacelets.blogspot.com/2006/06/creating-composite-controls-with-jsf.html
|