2012-01-13 93 views
0

我有一个数据表,带有用于选择的复选框。来自db的值显示为在数据表中被选中。当通过单击复选框进行新选择时,我可以从数组中读取后端的值,但是当取消选中复选框(取消选择该行)时,该数组仍然包含选中的复选框信息。我希望数组在提交时只有选中的复选框信息(以便我可以从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。

+0

我忘了提及,我使用PF RC1和JSF 2.0 – goodprg 2012-01-13 13:39:53

回答

相关问题