4 Replies Latest reply on Apr 13, 2010 1:55 AM by tonatiuh

    Problem building rich data table dynamically

    brenkeys

      Building rich data table dynamically



      Hi, i'm working with seam and rich faces, and i would like to know how to build a data table dinamically, i tried binding a property from a backing bean with the rich faces component for data table as follows:


      For the backing bean:


      import org.richfaces.component.html.HtmlDataTable;
      
      @Name("tableCreator")
      @Scope(ScopeType.SESSION)
      public class DataTableCreator(){
      
      public HtmlDataTable dataTable;
      
       /**Method that build the data table
       */
       public HtmlDataTable buildTable(){
         //Code here to create data Table (is already working...)
      
       }
      
       //getters and setters for dataTable
      
      }
      



      In the .xhtml file:


      <rich:dataTable id="table" binding="#{tableCreator.dataTable}" rows="10" ></rich:dataTable>



      I got the following exception:


      javax.faces.FacesException: javax.el.ELException: /view/creators/DataTableCreator.xhtml @92,92 binding="#{tableCreator.dataTable}": java.lang.IllegalArgumentException: argument type mismatch
           at com.sun.faces.application.ApplicationImpl.createComponent(ApplicationImpl.java:253)...
      



      The rich faces reference says (for rich:datatable component):


      component-type  : org.richfaces.DataTable


      component-class : org.richfaces.component.html.HtmlDataTable


      What am i doing wrong?? Any ideas please?? Thaks!

        • 1. Re: Problem building rich data table dynamically
          yasudevil

          I don't know if the way i'm describing here is the only way, but it's preety plain.


          The buildTable method should return a Collection like this


          public List<YourObject> buildTable(){ }



          Then in your rich dataTable you change the binding property to value. And add the var property wich is the one that will receive the iterate value


          <rich:dataTable id="table" value="#{tableCreator.dataTable}" 
          var="entry"
          rows="10" ></rich:dataTable>



          Than you populate your table using something like.


          <rich:column> #{entry.name} </rich:column>

          • 2. Re: Problem building rich data table dynamically
            brenkeys

            Hi, my problem is that i need to build the data table dynamically, i never know if i'm going to have 1,10 or 100 columns, and what are these columns going to contain for example a textBox or a combo. Do you have an idea how to build it completely dynamic?? Thank U :)


            By the way, i fixed something in the code because it's not necessary that the method buildTable returns a HtmlDataTable:




            import org.richfaces.component.html.HtmlDataTable;
            
            @Name("tableCreator")
            @Scope(ScopeType.SESSION)
            public class DataTableCreator(){
            
            public HtmlDataTable dataTable;
            
             /**Method that build the data table
             */
             public void buildTable(){
               //Code here to create data Table (is already working...)
            
             }
            
             //getters and setters for dataTable
            
            }
            



            • 3. Re: Problem building rich data table dynamically
              brenkeys

              Any ideas?? Come on guys!!! ;) I'm still trying to resolve this...

              • 4. Re: Problem building rich data table dynamically
                tonatiuh

                You need add the DataTable to panel


                See:




                <rich:panel id="panelModulos" binding="#{tableCreator.panelTable}">
                </rich:panel>
                





                And:




                |"~import org.richfaces.component.html.HtmlDataTable;
                
                @Name("tableCreator")
                @Scope(ScopeType.SESSION)
                public class DataTableCreator(){
                
                public HtmlDataTable dataTable;
                
                 public HtmlPanel panelTable () {
                   HtmlPanel panel = new HtmlPanel ();
                   panel.getChildren().add (buildTable());
                   return panel;
                 }
                
                 /**Method that build the data table
                 */
                 public HtmlDataTable buildTable(){
                   //Code here to create data Table (is already working...)
                
                 }
                
                 //getters and setters for dataTable
                
                }~"|