In the recipe Creating composition components in JSF 2.0, we passed different types of values to our composition component. In this recipe, we take a step forward and pass an action to it, instead of explicitly mapping the action in the composition component.
We have developed this recipe with NetBeans 6.8, JSF 2.0, and GlassFish v3. The JSF 2.0 classes were obtained from the NetBeans JSF 2.0 bundled library.
The solution is based on two steps:
… <x:tableColumn book="${bk}" attr="title" action="sortBooks" compbean="${booksStore}" /> …
… <h:commandLink action="#{compbean[action]}"> <h:outputText value="ascending" /> <f:param name="by" value="${attr}"/> <f:param name="order" value="ascending"/> </h:commandLink> …
That's all! Now you should be able to pass an action binding to create different elements such as toolbars.
As the standard EL can't help us here, we have used a little trick supported by Facelets—we have referenced the value binding in a generic way!