我有一个包含一堆行的 JSF 数据表,每行内部都有一个 selectOneMenu,如下所示:
<h:form
<h:dataTable id="myTable"
binding="#{myBean.dataTable}"
value="#{myBean.dataTableRows}" var="row"
first="0" rows="0" dir="LTR" frame="hsides" rules="all">
<h:column>
<f:facet name="header">
<h:outputText value="Sample Name" />
</f:facet>
<h:outputText value="#{row.sampleName}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Role" />
</f:facet>
<h:selectOneMenu value="#{row.role}"
id="roleInput">
<f:selectItems value="#{myBean.allRoles}" />
</h:selectOneMenu>
</h:column>
</h:dataTable>
<h:commandButton value="Save" action="#{myBean.save}" />
</h:form>
但是,我似乎无法弄清楚如何从保存方法的每一行中获取选定的角色。换句话说,我想保存每一行的值。我看到这篇文章,解释了如何保存输入文本框:
http://balusc.blogspot.com/2006/06/using-datatables.html#EditableDatatable
但它似乎不适用于 h:selectOneMenu 情况。有人有执行此操作的示例代码吗?
Thanks!
我看到你的桌子已经绑定到你的bean。在您的 bean 中,您可以使用 getDataTable() 方法并访问它。 Java 文档说:
public Object getRowData()
Return the data object representing the data for the currently selected row index, if any.
因此,如果您的代码如下:
List<String> selectedRowData = (List<String>) getDataTable().getRowData()
然后您可以访问用户选择的所有字段。我在我自己的项目及其工作中使用它。唯一的区别是我转换为我自己的类型而不是List<String>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)