2012-12-10 139 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