JSF Tip #55 - Adding a placeholder component to the component tree

Why would you add a placeholder component to the tree using ui:component? Well, sometimes you need to add content dynamically, but you also need to be able sure where it ends up.

Why would you need to know where it ends up? Well imagine the following scenario

    <ui:component id="component1">
        <ui:include rendered="#{myBean.include1Yes}" src="include1.xhtml"/>
    <ui:component id="component2">
        <ui:include rendered="#{myBean.include2Yes}" src="include2.xhtml"/>
    <ui:component id="component3">
        <ui:include rendered="#{myBean.include3Yes}" src="include3.xhtml"/>

Without the ui:component usage you would not know what the ids of each of the trees of the included content would be as the ids depends on how many subtrees are rendered. E.g. here it could render 3, 2, 1 or 0 subtrees. Which would make it be hard to find any component in those subtrees, but by using the ui:component tag you can use it as a starting point to look for the components in any of the subtrees.

Posted January 1, 2014