2012-12-10 63 views
2

我试图在表格中嵌入一个表格ah:panelGrid组件和h:selectOneMenu通过关闭它出现的单元格来调整格式设置,并创建一个新的(并且不需要的)行。JSF组件关闭表格单元格

我的代码看起来是这样的:selectOneMenu用于元素:

<h:panelGrid columns="2"> 
    [Other rows that work just fine] 
    <h:outputText value="Match [Stuff] to [More Stuff]:" /> 
    <table> 
     <tr> 
      <th>[Stuff]</th> 
      <th>[More Stuff]</th> 
     </tr> 
     <tr> 
      <td> 
       <h:outputText value="Manually Created First Element of Stuff" /> 
      </td> 
      <td> 
       <h:selectOneMenu value="#{bean.moreStuffSetting}"> 
        <f:selectItem itemLabel="--None--" itemValue="" /> 
        <f:selectItem itemLabel="Manual First Choice" itemValue="manual" /> 
        <f:selectItems 
         value="#{bean.listOfMoreStuff}" 
         var="moreStuff" 
         itemLabel="#{moreStuff.name}" 
         itemValue="#{moreStuff.value}" /> 
       </h:selectOneMenu> 
      </td> 
     </tr> 
     <ui:repeat value="#{bean.listOfStuff}" var="stuff"> 
      <tr> 
       <td> 
        <h:outputText value="#{stuff.name}" /> 
       </td> 
       <td> 
        <h:selectOneMenu value="#{bean.moreStuffSetting}"> 
         <f:selectItem itemLabel="--None--" itemValue="" /> 
         <f:selectItem itemLabel="Manual First Choice" itemValue="manual" /> 
         <f:selectItems 
          value="#{bean.listOfMoreStuff}" 
          var="moreStuff" 
          itemLabel="#{moreStuff.name}" 
          itemValue="#{moreStuff.value}" /> 
        </h:selectOneMenu> 
       </td> 
      </tr>  
     </ui:repeat> 
    </table> 
</h:panelGrid> 

与前h出现问题。 (然而,ui:repeat中的h:selectOneMenu元素完全符合我期望的)。我期待“手动创建东西的第一个元素”,并且该下拉列表在同一行中显示为两个单元格。但是,这是生成的HTML中显示的内容:

<tr> 
<td>Manually Created First Element of Stuff</td> 
<td> 
          </td> 
          <td></td> 
</tr> 
<tr> 
<td><select... 

两行。然而,在下面的嵌套一个,我得到这个:

    <tr> 
         <td>[Label I'm expecting] 
          </td> 
          <td><select... 

...这正是我期望它的行为。

我在做什么错?我是否以某种方式滥用JSF?在那里我没有看到有一些值得怀疑的错字吗?

回答

3

<h:panelGrid>选择JSF组件树中的第一个兄弟来启动一个新的表格单元格。您在那里的纯HTML <table>元素不是JSF组件。

将其包装在<h:panelGroup>中。

<h:panelGrid columns="2"> 
    <h:outputText value="Match [Stuff] to [More Stuff]:" /> 
    <h:panelGroup> 
     <table> 
      ... 
     </table> 
    </h:panelGroup> 
</h:panelGrid> 

另一种方法是用<h:dataTable>代替。

+0

宾果。复选标记是你的8分钟。谢谢! – BlairHippo

+0

不客气。 – BalusC