how can we select all current page items in rich:dataTable b
handsomeli Jul 5, 2008 9:49 PMHi:
Now I use rich:dataTable to show list data of type List. I add one column of h:selectBooleanCheckbox for user to choose muti items in the table . You can press a button to submit the selection at the same time. I add a boolean property to the WarningItem to get what items are selected where user click the submit button. It works.
For the convenience of the users, I want to add another h:selectBooleanCheckbox to control all other h:selectBooleanCheckbox in the rich:dataTable of the current page. However, I can not get the object list from rich:dataTable of the current page! So the problem is , I click that special h:selectBooleanCheckbox and make all items in the rich:dataTable selected ,including the items in other pages.
<h:form id="warningListForm" rendered="#{not empty warningQuery.resultList}"> <rich:dataTable id="warningList" rows="3" onRowMouseOver="this.style.backgroundColor='#F1F1F1'" onRowMouseOut="this.style.backgroundColor='#{a4jSkin.tableBackgroundColor}'" cellpadding="0" cellspacing="0" var="row" sortMode="single" value="#{resultList}"> <rich:column> <f:facet name="header"> <h:selectBooleanCheckbox value="#{warningQuery.selectall}">Select All <a:support event="onclick" actionListener="#{warningQuery.allSelect('resultList')}" reRender="ckSelect" /> </h:selectBooleanCheckbox> </f:facet> <h:selectBooleanCheckbox id="ckSelect" value="#{row.selected}"/> </rich:column> <rich:column sortBy="#{row.oldId}" rendered="#{user.hasField('oldid')}"> <f:facet name="header">ID</f:facet> #{row.oldId} </rich:column> </rich:dataTable> <h:commandButton action="#{warningQuery.updateStatus('1')}" value="action1"/> <h:commandButton action="#{warningQuery.updateStatus('3')}" value="action2"/> <br/> <rich:datascroller id="warningListScroller" align="left" for="warningList" maxPages="20" fastControls="hide"> <f:facet name="next"> <h:outputText value=">"/> </f:facet> <f:facet name="previous"> <h:outputText value="<"/> </f:facet> </rich:datascroller> </h:form>
@Stateful @Scope(ScopeType.SESSION) @Name("warningQuery") @SuppressWarnings(value={"unchecked","serial"}) public class WarningQueryBean implements WarningQuery { @DataModel private List<WarningItem> resultList; public void updateStatus(String status) { log.info("status="+status); log.info("status="+resultList.size()); if(resultList!=null){ for(WarningItem wi:resultList) { if(wi.isSelected()==true){ wi.setSelected(false); wi.setStatus(status); em.merge(wi); } } } selectall = false; } public void allSelect(String dataName){ Object o=Contexts.lookupInStatefulContexts(dataName); if(o!=null&&o instanceof javax.faces.model.DataModel){ javax.faces.model.DataModel dm=(javax.faces.model.DataModel)o; List<WarningItem> temList=(List<WarningItem>)dm.getWrappedData(); if(temList!=null&&temList.size()>0){ for(WarningItem wrap:temList){ // MAKE ALL ITEMS SELCTED,INCLUDING THE ONES IN OTHER PAGES wrap.setSelected(selectall); log.info("wrap="+wrap.getOldId()); } } } }
@Entity @Table(name = "warning_item") @SuppressWarnings(value={"serial"}) public class WarningItem implements Serializable{ @Logger Log log; Integer id; Integer oldId; boolean selected; //FOR THE h:selectBooleanCheckbox