2

I have the following <h:panelGrid>:

   <h:panelGrid columns="2" id="panelGrid" > 
        <!-- heading -->
        <f:facet name="header">
            User Details
        </f:facet>

        <h:outputLabel value="#{bundle.ViewUserdetailsLabel_id}"/>
        <!-- adding in a small effect here that will fade a message when a user hovers over the id number or username -->
        <h:outputLink id="id1" value="#">  
            <h:outputText id="id" value="#{userdetailsController.selected.id}" title="#{bundle.ViewUserdetailsTitle_id}"/> 
        </h:outputLink>                            

        <p:tooltip for="id" value="This is your I.D. Number" showEffect="fade" hideEffect="fade" />
        <h:outputText value="#{bundle.ViewUserdetailsLabel_username}"/>
        <h:outputLink id="username1" value="#">  
            <h:outputText id="username" value="#{userdetailsController.selected.username}" title="#{bundle.ViewUserdetailsTitle_username}"/>
        </h:outputLink>                            
        <p:tooltip for="username" value="Your registered username, this can be changed" showEffect="fade" hideEffect="fade" />

        <f:facet name="footer"></f:facet>  

    </h:panelGrid>

I expected it to show up as

User Details
Id:          500
Username:    zzzzzzzz

However, instead it show up with some empty cells:

User Details
             Id:
             500
             Username:
zzzzzzzz

The same problem perists when I use <p:panelGrid> instead of <h:panelGrid>. How is this caused and how can I sovle it?

1 Answer 1

8

In a panel grid each immediate child component counts as a single table cell.

Those <!-- heading --> and <!-- adding ... --> comment lines count each as a single child. Those thus also counts each as a single table cell.

To solve it, just tell Facelets to skip all comments during view build time by the following web.xml entry:

<context-param>
    <param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
    <param-value>true</param-value>
</context-param>

Then there's the <p:tooltip> which also counts as a single table cell even though it does not represent any immediate content. You need to wrap the tooltip and its target component in a <h:panelGroup> so that it represents a single table cell (additionally, you could alternatively also just put the comment in there).

<h:outputLabel value="#{bundle.ViewUserdetailsLabel_id}"/>
<h:panelGroup>
    <!-- adding in a small effect here that will fade a message when a user hovers over the id number or username -->
    <h:outputLink id="id1" value="#">  
        <h:outputText id="id" value="#{userdetailsController.selected.id}" title="#{bundle.ViewUserdetailsTitle_id}"/> 
    </h:outputLink>                            
    <p:tooltip for="id" value="This is your I.D. Number" showEffect="fade" hideEffect="fade" />
</h:panelGroup>

<h:outputText value="#{bundle.ViewUserdetailsLabel_username}"/>
<h:panelGroup>
    <h:outputLink id="username1" value="#">  
        <h:outputText id="username" value="#{userdetailsController.selected.username}" title="#{bundle.ViewUserdetailsTitle_username}"/>
    </h:outputLink>                            
    <p:tooltip for="username" value="Your registered username, this can be changed" showEffect="fade" hideEffect="fade" />
</h:panelGroup>
3
  • Thanks that has partially solved it, it looks like it is also counting the ' <p:tooltip ' as a table cell, is there any way to stop this too ? Commented Nov 19, 2013 at 11:44
  • 1
    Found the solution is to move these as it is not required to have them by the object, thanks a lot for you help :) Commented Nov 19, 2013 at 11:46
  • 1
    Overlooked those tooltips. Put them in <h:panelGroup>. I updated the answer. Note that you can do the same for comments.
    – BalusC
    Commented Nov 19, 2013 at 11:53

Not the answer you're looking for? Browse other questions tagged or ask your own question.