Facelets (Source) Tags
These are a key feature of facelets but there are no examples and the reference manual gives gives only the bare bones.
Example - Requirement
Resuable Yes/No Buttons which can have custom actions defined.
Use - examplePage.xhtml
Add xmlns:my="http://my.com/jsf/my" to your namespace definitions
Use the tag:
<my:yesNoButtons yesBean="The specified item was not found." yesAction="deleteUser" noBean="" noAction="deleteCity" />
Source - yesNoButtons.xhtml
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:h="http://java.sun.com/jsf/html"> <ui:composition> <h:commandButton value="Yes" action="#{yesBean[yesAction]}"></h:commandButton> <h:commandButton value="No" action="#{noBean[noAction]}"></h:commandButton> </ui:composition> </html>
Wiring
These files live in WEB-INF.
facelets taglib - my.taglib.xml
<!DOCTYPE facelet-taglib PUBLIC "-//Sun Microsystems, Inc.//DTD Facelet Taglib 1.0//EN" "http://java.sun.com/dtd/faces-taglib_1_0.dtd"> <facelet-taglib> <namespace>http://my.com/jsf/my</namespace> <tag> <tag-name>yesNoButtons</tag-name> <source>yesNoButtons.xhtml</source> </tag> </facelet-taglib>
Web.xml - web.xml
... <context-param> <param-name>facelets.LIBRARIES</param-name> <param-value>/WEB-INF/my.taglib.xml</param-value> </context-param> ...
Of course, you could also apply a default style to your buttons, allow i8ln messages to be used as button labels, theme the buttons, allow view-id's to be passed for navigation...
Comments