1 Reply Latest reply on Nov 16, 2007 7:36 AM by Joel Meurisse

    How to get selected rows?

    Ken Liang Newbie

      Hi, I am new to RichFaces, I have a beginner question here.

      I have a search result for 100 records shown in 10 pages. I select some on page 1, 2 and 3 by checking the checkbox. How can I get the selected rows in back bean?

      Thank you for help!!

      <rich:simpleTogglePanel label="Schools" immediate="true" switchType="client">
       <tr:panelFormLayout rows="1">
       <tr:inputText label="School Name:" value="#{searchCriteria.name}"/>
       <f:facet name="footer">
       <tr:panelButtonBar>
       <tr:commandButton text="Search Schools" action="#{schoolQuery.initialSearch}" blocking="true"/>
       </tr:panelButtonBar>
       </f:facet>
       </tr:panelFormLayout>
      </rich:simpleTogglePanel>
      
      <rich:dataTable id="schoolTable" value="#{schoolQuery.richModel}" var="item" rows="10" width="100%" frame="box">
       <f:facet name="header">
       <rich:datascroller for="schoolTable" renderIfSinglePage="false" binding="#{jsfBinding.datascroller}" ajaxSingle="false"/>
       </f:facet>
       <rich:column>
       <f:facet name="header">Name</f:facet>
       <h:outputText value="#{item.name}"/>
       </rich:column>
       <rich:column>
       <f:facet name="header">Select</f:facet>
       <tr:selectBooleanCheckbox value="#{item.selected}"/>
       </rich:column>
      </rich:dataTable>
      


        • 1. Re: How to get selected rows?
          Joel Meurisse Newbie

          I used a binding to a UIData object e.g. schoolTableData)

          something like:

          <rich:dataTable id="schoolTable" binding="#{yourBean.schoolTableData}" ...
          
          
          In your controller bean:
          
           UIData table = yourBean.getSchoolTableData();
           for (int rowIndex = 0; rowIndex < table.getRowCount(); rowIndex++) {
           // Select the a row (if there is one)
           table.setRowIndex(rowIndex++);
          
           SchoolQuery schoolQuery= (SchoolQuery) table.getRowData();
           if (schoolQuery == null) return null;
          
           //check only the selected entries
           if(!schoolQuery.isSelected())
           continue;