我试图在 h:panelGrid 组件中嵌套一个表格,而 h: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:selectOneMenu 元素出现问题。 (但是,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?是不是有一些我没有看到的值得一看的错别字?
最佳答案
<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>
相反。
关于JSF 组件关闭表格单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13808017/