3 Replies Latest reply on Nov 22, 2011 9:09 AM by Rubén Darío López Rojas

    How to get the rendered rows of a dataTable?

    Rubén Darío López Rojas Newbie



      I have a table (ExtendedDataTable with ExtendedTableDataModel as dataModel) in wich the user can sort columns and filter the rows, the table is also paginated (DataScroller). For example:






        rows="50" ... >








          <h:outputText value="#{_entity.code}" />




        <f:facet name="footer">

          <rich:datascroller id="ds" />





      My question is, How can I get the rendered data after filtering and sorting?


      I'm using RichFaces 3.3. Thanks in advance.

        • 1. Re: How to get the rendered rows of a dataTable?
          Christian Peter Expert

          instead of value="#{datamodel}" being somekind of List<?>, you have to use an ExtendedTableDataModel (I'm not quite sure what the correct name was) or a ModifyableDataModel. After clientside filtering you can retrieve the actual visible rows (including pagination).


          from: http://community.jboss.org/wiki/HowToGetFilteredDataFromTableToList :


          public ModifiableModel getDataModel() {
               if (this.DataModel == null) {
                    ExtendedTableDataModel<MyDataObj> model = new ExtendedTableDataModel<MyDataObj>(new DataProvider<MyDataObj>() {
                         private static final long serialVersionUID = 5054087821033164847L;

                         public MyDataObj getItemByKey(Object key) {
                              for (MyDataObj c : MyManagedBean.this.data) {
                                   if (key.equals(getKey(c))) {
                                        return c;
                              return null;

                         public List<MyDataObj> getItemsByRange(int firstRow, int endRow) {
                              return MyManagedBean.this.data.subList(firstRow, endRow);

                         public Object getKey(MyDataObj item) {
                              return item.getId();

                         public int getRowCount() {
                              return MyManagedBean.this.data.size();

                    this.dataModel = new ModifiableModel(model, "row");

               return this.dataModel;



          public List<MyDataObj> getFilteredData() throws IOException {
                    final List<MyDataObj> filteredData = new ArrayList<MyDataObj>();
                    final ModifiableModel model = getDataModel();

                    getDataModel().walk(FacesContext.getCurrentInstance(), new DataVisitor() {
                              public void process(FacesContext context, Object rowKey, Object argument) {
                                        filteredData.add((MyDataObj) model.getRowData());
                    }, new SequenceRange(0, -1), null);

                    return filteredData;





          • 2. Re: How to get the rendered rows of a dataTable?
            Rubén Darío López Rojas Newbie



            That was waht I was looking for. Next time I will check out the knowledge base before asking



            • 3. Re: How to get the rendered rows of a dataTable?
              Rubén Darío López Rojas Newbie

              Finally I used an ExtendedTableDataModifiableModel<T> instead of a ModifiableModel to make row selection work correctly on the ExtendedDataTable.


              Thanks again.