6 Replies Latest reply on Aug 11, 2009 4:56 AM by Pavel Zelenka

    rich:datatable - how to get rows

    Pavel Zelenka Newbie

      Hi,

      I have rich:datatable and I use filterBy feature. How can I get data which are actually viewed?

      Thanks

        • 1. Re: rich:datatable - how to get rows
          Ilya Shaikovsky Master

          you should implement data model properly. see modifiable model sample at richfaces-demo.

          • 2. Re: rich:datatable - how to get rows
            Pavel Zelenka Newbie

             

            "ilya_shaikovsky" wrote:
            you should implement data model properly. see modifiable model sample at richfaces-demo.


            Thanks, but I think don't understand it. Maybe it's too complicated for me. I have very simple data table:
            <rich:dataTable id="table" value="#{MyBean.carList}" var="item" rows="25"> The only thing I need is when user clicks a button in the page to iterate actually viewed data from data table.

            • 3. Re: rich:datatable - how to get rows
              Ilya Shaikovsky Master

              check richfaces-demo all samples placed at dataTable menu item.

              • 4. Re: rich:datatable - how to get rows
                John Doe Newbie

                You don't need to write a whole custom DataModel.

                Construct your Bean like this:

                int currentCarListIndex = 0;
                Car currentCar;
                
                public Car getCurrentCar()
                {
                 return currentCar;
                }
                
                public void setCurrentCar(Car c)
                {
                 this.currentCar = car;
                }
                
                public void nextCar()
                {
                 //TODO: bounds check
                 currentCar = carList.get(currentCarListIndex++);
                }
                


                Then construct your datatable like this:

                <rich:dataTable
                 id="datatable"
                 rows="20"
                 var="item" value="#{MyBean.carList}"
                 >
                
                 <rich:column>
                 <f:facet name="header">Actions</f:facet>
                 <a4j:commandLink id="editlink" >
                 <h:graphicImage value="/img/edit.gif" style="border:0"/>
                 <f:setPropertyActionListener value="#{item}" target="#{MyBean.currentCar}" />
                 </a4j:commandLink>
                 </rich:column>
                 <rich:column> <!-- just some column for output -->
                 <h:outputText value="#{item.engineDescription}
                 </rich:column>
                 </rich:datatable>
                <a4j:commandLink id="NEXT" value="NEXT CAR" action="#{MyBean.nextCar()}" />
                 <h:outputText value="#{MyBean.currentCar.engineDescription}" />
                

                HTH


                • 5. Re: rich:datatable - how to get rows
                  Pavel Zelenka Newbie

                   

                  "JohnDoe123" wrote:
                  You don't need to write a whole custom DataModel.

                  Construct your Bean like this:



                  Thanks, but I don't need one particular row. I need all rows viewed which may be filtered via filterBy feature.

                  • 6. Re: rich:datatable - how to get rows
                    Pavel Zelenka Newbie

                    The solution is very simple. Just to use HtmlDataTable and iterate through rows.

                    for (int i = 0; i < htmlDataTable.getRowCount(); i++) {
                    htmlDataTable.setRowIndex(i);
                    Car c = (Car) htmlDataTable.getRowData();
                    ....
                    }