4 Replies Latest reply on Jul 26, 2012 10:17 AM by snjv180

    Binding List with a datatable

    snjv180

      I want to ask anyone if this can be done. I have to bind two or more lists with a datatable dynamically.

       

      I mean if I have <rich:dataTable value="#{listBean.List1}" var="list" id="table" > the when I press a command button it may load List2

       

      so if I press the command button the it must be <rich:dataTable value="#{listBean.List2}" var="list" id="table" rows="30">

       

      Now my question is would something like this work

       

      <rich:dataTable value="#{listBean.toggleList}" var="list" id="table" >

       

      and the commandbutton can send some parameter which would make the toggling possible.

       

      public List<String> toggleList(){

       

                          if(listparam==true){

                                    return this.list1;

                          }

                          else{

                                    return this.list2;

                          }

       

      Is this a feasible way or is there a simpler way to do it. I think it is feasible but I just want some plain advice.

        • 1. Re: Binding List with a datatable
          healeyb

          I'm not sure that I'm quite with you just yet, can you provide an example of what one list would be, list1, and then list2.

           

          Regards,

          Brendan.

          • 2. Re: Binding List with a datatable
            snjv180

            Hello Brendan,

                What I'm trying to do is I have a huge amount of data. I want to extract a sublist of this list and show this to the user. This sublist must change accordingly as we sort ascendingly or descendingly. We must be able to filter these data as well. So I just want to bind the rich datatable to the sublist that is the output. But I want the sorting and the Filtering operation to be performed within the whole list of data. This filtering and sorting operations must be done in all columns . I hope this is enough information. Thank you for the quick reply.

            • 3. Re: Binding List with a datatable
              healeyb

              Ok, I'm not sure that the list/sublist scenario quite fits but a dataTable will display a list which can be made to include the required

              information based upon user input. You don't want to be accessing the database from a getter with JSF so you'd typically have say

              a List<User> allUsers  in the bean and then <rich:dataTable value="#{bean.allUsers}" .../>. A commandButton/Link action method

              could then rebuild the list and render= the dataTable to display refreshed information. I generally initially build the list in a

              preRenderView event listener so that data is available on page load, or perhaps in a tab change listener.

               

              The dataTable and extendedDataTable suppport lazy loading, sorting and filtering but be warned that this is fairly complex and you

              want to allocate a good amount of time for this task. I don't feel that there are plentiful good examples showing this more complex

              usage of the data iteration components and the best advice I can give you is to get on amazon and order a copy of Ilya's book

              Practical Richfaces 2, which does contain good examples of this.

               

              For lazy loading the value attribute of rich:dataTable references an implementation of a class which extends

              org.ajax4jsf.model.ExtendedDataModel, again it's best to refer to the book to figure out how to do this.

               

              The showcase could do with a bit more work in this area, for example if you check the filtering example in the showcase you'll

              find that the xhtml and backing bean code don't quite match up (try and find allInvnetoryItems - I can't):

               

              http://showcase.richfaces.org/richfaces/component-sample.jsf?demo=dataTable&skin=blueSky

               

              So you can do everything you require but don't expect to get it done in a day.

               

              Regards,

              Brendan.

              • 4. Re: Binding List with a datatable
                snjv180

                Thank you for the great answer.

                 

                I have the book and now I'm going to read it in full depth. I feel that datatable should be enough because I have a navigation panel that has a list like this

                1>>2>>3>>4>>5. This is what I need to implement. Yes I was working on the showcase code my self but when I sorted ,the sorting was done against first a primary column and then a secondary column. Maybe some thing went wrong.

                 

                Thank you!