2 Replies Latest reply on Sep 15, 2012 7:51 AM by mcmurdosound

    Get row Values of RichDataTable

    godoy

      Is there a way to get the column values of a richDataTable through the binding attribute

      can get the values of the header, now I need a way to read tds table rows,

      but only the rows that are being displayed on the table, I can not use the getValue () of dataTable

      Anyone know how to solve this?

      see my code

       

      <rich:dataTable id="racpTb" value="#{racpMBean.model}" var="item" binding="#{racpMBean.tb}" >

                                                        <rich:column>

                                                                  <f:facet name="header"> 

                                                                                      <h:outputText value="Número - Ação" />  

                                                                  </f:facet>

                                                                  <h:outputText value="#{item.numeroDocumento} - " />

                                                        </rich:column>

      ...

      and in bean:

       

      // i get values from facet header

      HtmlDataTable tb = new HtmlDataTable();

                public void runConversion(ActionEvent evt) {

                          List<UIComponent> colunas = tb.getChildren(); 

      for (UIComponent ui : colunas) {

                                    List<UIComponent> childs = ui.getFacet("header").getChildren();

                                    for (UIComponent child : childs) {

                                              if (child instanceof HtmlOutputText) {

                                                        HtmlOutputText out = (HtmlOutputText) child;

                                                out.getAttributes();

                                              }

                                    }

                          }

       

      Any idea?

      Thanks.

        • 1. Re: Get row Values of RichDataTable
          mcmurdosound

          You have to use a DataVisitor to walk the tables model.

           

          public void walkExtDT(String id) throws IOException {

              FacesContext ctx = FacesContext.getCurrentInstance();

              UIComponent component = ctx.getViewRoot().findComponent(id);

              log.debug("component #0", component);

           

              if (component != null && component instanceof HtmlExtendedDataTable) {

                final HtmlExtendedDataTable t = (HtmlExtendedDataTable) component;

           

                t.captureOrigValue(ctx);

           

                DataVisitor visitor = new DataVisitor() {

           

                  @Override

                  public void process(FacesContext context, Object rowKey, Object argument)

                      throws IOException {

                    t.setRowKey(rowKey);

                    Iterator<UIColumn> colIter = t.getChildColumns();

                    while (colIter.hasNext()) {

                      UIColumn col = colIter.next();

                      List<UIComponent> children = col.getChildren();

                      for (UIComponent c : children) {

                        if (c instanceof UIOutput) {

                          System.out.println(((UIOutput) c).getValue());

                        }

                      }

                    }

           

                  }

           

                };

           

                t.walk(ctx, visitor, null);

           

                t.restoreOrigValue(ctx);

                t.setRowKey(null);

              }

           

            }

          1 of 1 people found this helpful
          • 2. Re: Get row Values of RichDataTable
            mcmurdosound

            ah sorry, my example is for the extendedDataTable. To use with the standard datatable you'll have to change to HtmlDataTable. This should do the trick.

            No componentbinding required! Just pass the clientId of the table to the method.