According to the tag library for http://xmlns.jcp.org/jsf/html, a h:panelGroup
is
Intended for use in situations when only one UIComponent child can be nested, such as in the case of facets. If the "style" or "styleClass" attributes are present, and the "layout" attribute is present with a value of "block", render a "div" element, outputting the value of the "style" attribute as the value of the "style" attribute and the value of the "styleClass" attribute as the value of the "class" attribute. Otherwise, if the "layout" attribute is not present, or the "layout" attribute contains a value other than "block", render a "span" element, outputting the value of the "style" attribute as the value of the "style" attribute, and the value of the "styleClass" attribute as the value of the "class" attribute.
In case of
<h:panelGroup id="id" layout="block">
<!-- ... --->
</h:panelGroup>
or
<h:panelGroup layout="block" style="margin-right: 10px;">
<!-- ... --->
</h:panelGroup>
a div
is being rendered:
<div id="id">
</div>
respective
<div style="margin-right: 10px;">
</div>
but when omitting the id
(if one don't want to update
the panelGroup
) or the style
(if one don't want to style the panelGroup
) no div
is being rendered and the resulting HTML can mess up ones layout. Furthermore exploring the realm of JSF, a panelGroup
can also be used to conditionally render child elements using its rendered
flag but as mentioned before when omitting the two mentioned attributes the result is rendered conditionally but without a div
, such as
<h:panelGroup layout="block" rendered="true">
<it>Without DIV.</it>
</h:panelGroup>
leads to
<it>Without DIV.</it>
After this inquiry I want to check with the Stackoverflow community that I understood it right that when not using a panelGroup
as a naming container or to customary style its elements one is better off solving the conditional rendering part (if needed) using a ui:fragment
and the layouting part with a hard-coded div
. Is this so?
Note: we are talking about if h:panelgroup
will render any HTML component, but unless render="false"
the inner components are not blocked from rendering in any case.
The behaviour tree of h:panelgroup
consists of two checks:
Is at least one of "id" or "style" or "styleClass" attributes set?
Yes:
a. Renders a <div>
if layout="block", otherwise
b. Renders a <span>
(layout="gibberish" or non-existant)
No:
<f:facet>
)The test for the layout attribute only comes after 1., above. Since your third example goes into the no branch, it is ignored.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With