Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

panelGroup without style or styleClass is not rendered unless ID is given

Tags:

jsf

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?

like image 982
Smutje Avatar asked Sep 22 '14 12:09

Smutje


1 Answers

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:

  1. 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:

  2. Renders no html component. Still useful if you want to use "rendered" or when you can nest only one component (i.e. <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.

like image 97
Mindwin Avatar answered Nov 16 '22 05:11

Mindwin