I have one page main.xhtml, which contains ui:composition. This composition uses template1.xhtml file. template1.xhtml file contains ui:insert, ui:include tag which are pointing to template2.xhtml file. Now, I want to use parameters that are passed from ui:composition inside template2.xhtml.
main.xhtml
<ui:composition template="template1.xhtml">
<ui:param name="a1" value="val1"/>
</ui:composition>
template1.xhtml
<ui:insert name="header">
<ui:include src="template2.xhtml">
</ui:insert>
template2.xhtml
<h:panelGroup rendered="#{not empty a1}" layout="block">
<h4>#{a1}</h4>
</h:panelGroup>
My question is can I directly access parameter named a1 or I had to again pass ui:param in ui:include?
Depends on Facelets version and JSF impl/version.
In original Facelets 1.x, any
<ui:param>in parent composition is inherited into all<ui:include>children.In Facelets 2.x as integrated in JSF 2.x, any
<ui:param>of a parent composition which ought to be reused in an<ui:include>(or<ui:decorate>) must be explicitly passed through.At least, that's the case when you're using Mojarra 2.x. In MyFaces 2.0 / 2.1, however, it was not necessary as the original Facelets 1.x behavior unintentionally slipped into MyFaces 2.0 / 2.1.
They have fixed it in MyFaces 2.2, so you need to explicitly pass them through.
In case you're using MyFaces 2.2 or newer, and want to retain the original Facelets 1.x behavior, then you can add the following context param to
web.xml:No such context param exist for Mojarra, so this should not be relied upon in case you want to have your code to work the same across all JSF implementations.