9

How do I add an empty element in a JSF panelGrid?

This is my full table:

<h:panelGrid columns="2">
    <h:outputLabel value="row1"/>
    <h:outputLabel value="row2"/>

    <h:outputLabel value="row1"/>
    <h:outputLabel value="row2"/>

    <h:outputLabel value="row1"/>
    <h:outputLabel value="row2"/>
</h:panelGrid>

How do I add an empty element? What is the advised way? (adding an empty outputlabel? This does not feel correct.)

<h:panelGrid columns="2">
    <h:outputLabel value="row1"/>
    <h:outputLabel value="row2"/>

    <!-- This need to be emtpy -->
    <h:outputLabel value="row2"/>

    <h:outputLabel value="row1"/>
    <h:outputLabel value="row2"/>
</h:panelGrid>
Dimitri Dewaele
  • 10,311
  • 21
  • 80
  • 127
  • "Empty" does mean only its `value` should remain empty? Why does not this `` suffice, if such is a case? For what purpose is an empty `` needed? It should be as good as it does not exist at all. Doesn't it? – Tiny Feb 19 '15 at 16:14
  • Ola! Adding does work! Is this the best practice? Please answer. I need an empty cell for layout reasons. – Dimitri Dewaele Feb 19 '15 at 16:16
  • All other potential readers of this post should have already precisely understood the question but I have not yet understood - a silly mind :) – Tiny Feb 19 '15 at 16:21

2 Answers2

19

Use an empty <h:panelGroup>.

<h:panelGrid columns="2">
    <h:outputLabel value="row1"/>
    <h:outputLabel value="row2"/>

    <h:panelGroup />
    <h:outputLabel value="row2"/>

    <h:outputLabel value="row1"/>
    <h:outputLabel value="row2"/>
</h:panelGrid>

See also:


Unrelated to the concrete problem, are you in basic HTML terms very well aware of when you should be using <h:outputLabel> instead of <h:outputText>? If not, carefully read Purpose of the h:outputLabel and its "for" attribute.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • This puzzles me: also represents an empty cell... what to prefer? – Dimitri Dewaele Feb 20 '15 at 09:26
  • 3
    Bad idea. Facelets can be configured to remove comments. See also e.g. http://stackoverflow.com/questions/3388109/how-can-i-remove-html-comments-in-my-facelets – BalusC Feb 20 '15 at 09:30
0

If you don't need to change dynamically the content of the cell, and need only an empty cell, probabily using <h:outputText/> is more efficient than adding a component <h:panelGroup /> to the page structure:

<h:panelGrid columns="2">
  <h:outputLabel value="row1"/>
  <h:outputLabel value="row2"/>

  <h:outputText/>
  <h:outputLabel value="row2"/>

  <h:outputLabel value="row1"/>
  <h:outputLabel value="row2"/>
</h:panelGrid>
Bruno F
  • 31
  • 3