【发布时间】:2012-01-13 13:12:20
【问题描述】:
我有一个带有复选框的数据表供选择。来自 db 的值在数据表中显示为已选中。当通过单击复选框进行新选择时,我可以从数组中读取后端中的值,但是当我取消选中复选框(取消选择该行)时,该数组仍然包含选中的复选框信息。我希望数组在提交时仅选中复选框信息(以便我可以从数据库中删除未选中的复选框)。这是代码-
<p:dataTable id="stdList"
value="#{stdController.students}"
selection="#{stdController.selectedStudents}"
var="item"
rows="10"
rowKey="#{item.id}"
>
<p:column selectionMode="multiple" />
<p:column
sortBy="#{item.name}"
filterBy="#{item.name}"
filterStyle="display: none;"
>
<f:facet name="header">
<h:outputText value="#{prop.name}"/>
</f:facet>
<h:outputText value="#{item.name}"/>
</p:column>
</p:dataTable>
我的支持 bean 是 -
public Topics[] getSelectedStudents() {
Students[] returnStudents = new Students[getSelectedStudentsAsList().size()]; // //this gets the list from db and creates the array here.
getSelectedStudentsAsList().toArray(returnStudents);
return returnStudents;
}
public void setSelectedStudents(Students[] selectedStudents) {
getSelected().setStudents(new HashSet<Topics>(Arrays.asList(selectedStudents)));
}
非常感谢任何帮助。 TIA。
【问题讨论】:
-
我忘了说,我正在使用 PF RC1 和 JSF 2.0
标签: primefaces