【问题标题】:Reading unselect values of checkboxes in datatable primefaces读取数据表素面中复选框的取消选择值
【发布时间】: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


【解决方案1】:

JQuery 中有一个 bug,它会影响 PrimeFaces,但仍未修复。 检查这个:http://code.google.com/p/primefaces/issues/detail?id=3205 您可以使用字符串作为行标识符作为解决方法(例如 item.name)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-11-10
    • 2015-12-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-14
    相关资源
    最近更新 更多