JSF panelGroup example
Introduction
JSF panelGroup may be used as a container to other JSF components. Basically it will render a div or a span depending on the configuration we set.
The layout attribute
The layout attribute of the panelGroup will determine how the panelGroup will be rendered. panelGroup is rendered by default as a span. If the layout attribute has the value block then it will be rendered as a div.
<h:panelGroup layout="block" id="container"> <h:outputText value="I will be rendered inside a div" /> </h:panelGroup>
The previous panelGroup will be rendered as:
<div id="container"> I will be rendered inside a div </div>
Now if we ommit the layout attribute:
<h:panelGroup id="container"> <h:outputText value="I will be rendered inside a span" /> </h:panelGroup>
The panelGroup will now be rendered as a span:
<span id="container"> I will be rendered inside a span </span>
The styleClass attribute
The styleClass attribute will determine the class attribute of the generated HTML element (the CSS class used for the element):
<h:panelGroup layout="block" id="container" styleClass="someClass"> <h:outputText value="I will be rendered inside a div" /> </h:panelGroup>
Will be rendered as:
<div id="container" class="someClass"> I will be rendered inside a div </div>
The rendered attribute
The rendered attribute will determine if the component should be rendered by JSF:
<h:panelGroup layout="block" id="container" rendered="#{someBean.renderPanel}"> <h:outputText value="I will be rendered inside a div" /> </h:panelGroup>
If the render expression evaluates to true the component is rendered by JSF, otherwise the component is not rendered.