h:panelGrid呈现空表格单元格

时间:2013-11-19 11:32:54

标签: jsf primefaces panelgrid

我有以下<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>

我希望它显示为

User Details
Id:          500
Username:    zzzzzzzz

然而,它显示了一些空单元格:

User Details
             Id:
             500
             Username:
zzzzzzzz

使用<p:panelGrid>代替<h:panelGrid>时,问题仍然存在。这是怎么造成的,我该如何解决呢?

1 个答案:

答案 0 :(得分:8)

在面板网格中,每个直接子组件都计为单个表格单元格。

这些<!-- heading --><!-- adding ... -->条评论行将每个评为一个孩子。因此,这些也将每个计为单个表格单元格。

要解决此问题,只需通过以下web.xml条目告诉Facelets在视图构建期间跳过所有注释:

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

然后有<p:tooltip>,它也算作单个表格单元格,即使它不代表任何直接内容。您需要将工具提示及其目标组件包装在<h:panelGroup>中,以便它表示单个表格单元格(此外,您也可以将注释放在那里)。

<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>