How to pass parameters to JSF 2.0 template file?
In JSF 2.0 web application, you can use “ui:param” facelets tag to pass parameters to an include file or a template file.
1. Parameter in “ui:include”
Example to pass a “tagLine” parameter to an include file.
<ui:insert name="header" > <ui:include src="/template/common/commonHeader.xhtml"> <ui:param name="tagLine" value="JSF a day, bug away" /> </ui:include> </ui:insert>
In the commonHeader.xhtml file, you can access the “tagLine” parameter with a normal EL expression.
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets" > <body> <ui:composition> <h2>Tag Line : #{tagLine}</h2> </ui:composition> </body> </html>
2. Parameter in “ui:composition”
Example to pass a “curFileName” parameter to a template file.
<ui:composition template="template/common/commonLayout.xhtml"> <ui:param name="curFileName" value="default.xhtml" /> </ui:composition>
In the commonLayout.xhtml file, you can access the “curFileName” parameter with a normal EL expression.
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets" > <h:body> <div id="content"> Current File : #{curFileName} </div> </h:body> </html>








[...] How to pass parameters to JSF 2.0 template file? JSF 2 <ui:param> example, pass parameter to an include file or template file. [...]
This is the simplest explanation of UI:Param I found online. Thanks!