1 2 Previous Next 18 Replies Latest reply on May 26, 2008 8:37 PM by asavitsky

    Which component for a sortable list?

    wachtda.scsi.gmx.ch

      I now invested many hours to implement a sortable list for my application, but I'm still not happy with my solution.


      I found two different possibilities to implement a sortable list:


      1.) Work with the normal h:datatable tag and implement the sort possibility trough a backing bean.


      2.) Implement the list with a trinidad table component which can sort the different columns.


      I realized for both possibilities some limitations!


      Possibility 1:

      - Sorting trough a backing bean (as discussed in the old forum) does not fit very well in the seam concept. (seperating of concerns) because sorting belongs to the view!

      - Sorting trough a structure of different object (e.g. facility.name, facility.datalogger.device.name) is tricky.


      Possibility 2:

      - The trindidad generated code is very overloaded.

      - Because of some JSF limitations I'm not able to pass object as variables, but only strings.

      - If I have a list (via Datamodel) the list will be loaded on each access, this happens until I use the trinidad components.


      What Is your aproach to implement sortable a list?
      (With structured sorting, e.g. facility.name, facility.datalogger.device.name within the application, no db access)


      For ideas and examples I will be very happy cause I think sortable lists are essential in very complex application!
      Greetings Daniel

        • 1. Re: Which component for a sortable list?
          pmuir

          I would use EntityQuery.

          • 2. Re: Which component for a sortable list?
            wachtda.scsi.gmx.ch

            Hello Pete


            I not very pleased with EntityQuery because they have to be created all at a central place (components.xml) and not there were they are actually used...


            Or am I wrong?

            • 3. Re: Which component for a sortable list?
              brachie

              What if I want to display associated objects in a sortable datatable like:


              <tr:table value="#{person.tasks}> 
              ...



              In this case Hibernate returns a collection of tasks for the person. Should I create an EntityQuery fetching all tasks for the person in my backing bean and use this with the table?


              I ask, because in our application we use this type of tables very often. It would be a pain to write an EntityQuery for each associated object collection. Are there other possibilities with less overhead?


              Regards,


              Alexander

              • 4. Re: Which component for a sortable list?
                brachie

                Daniel Wachter wrote on Mar 12, 2008 08:05 AM:


                ...
                - If I have a list (via Datamodel) the list will be loaded on each access, this happens until I use the trinidad components.
                ...


                Hi,


                I also realized that behavoir with my trinidad table. Each time I click the header to sort it or page through the results, the lists I also use on that page (e.g. in a h:selectManyList) will be reloaded (at least the getter is called). This leads to a noticeable performance loss when having several entries in the selectManyList. When I use tr:selectManyList instead (the trinidad component) the getter is not called...


                Is there anyone who could tell me the reason for that?


                Regards,


                Alexander

                • 5. Re: Which component for a sortable list?
                  pmuir

                  You can create them in a /com/acme/components.xml or you can use extension as well.

                  • 6. Re: Which component for a sortable list?
                    pmuir

                    Alexander Seitz wrote on Mar 12, 2008 12:22 PM:


                    I ask, because in our application we use this type of tables very often. It would be a pain to write an EntityQuery for each associated object collection. Are there other possibilities with less overhead?



                    The minimum is 1 line of xml needed per entity query - you want less than that?

                    • 7. Re: Which component for a sortable list?
                      pmuir

                      Alexander Seitz wrote on Mar 12, 2008 12:29 PM:


                      I also realized that behavoir with my trinidad table. Each time I click the header to sort it or page through the results, the lists I also use on that page (e.g. in a h:selectManyList) will be reloaded (at least the getter is called). This leads to a noticeable performance loss when having several entries in the selectManyList. When I use tr:selectManyList instead (the trinidad component) the getter is not called...

                      Is there anyone who could tell me the reason for that?



                      Look at putting the query into a longer scope - but then you will need to manually refresh the data.

                      • 8. Re: Which component for a sortable list?

                        I'm not sure, if I got your right pete.


                        so you suggest to have onen parent table iterating over some PersonEnityQuery and for each Person you would call the PersonTaskEntityQuery, like that?


                        <h:dataTable id="personList" var="person" value="#{personEntityQuery.resultList}">
                        
                          <h:column>#display some person data: #{person.Name}<h:column>
                        
                          <h:column>
                            <h:dataTable id="personTaskList" var="task" value="#{taskEntityQuery.resultList(person.id)}">   
                              
                              #{task.Name}
                        
                            </h:dataTable>
                          </h:column>
                        
                        </h:dataTable>



                        but that would mean to have 1+n selects on the page (where n is the number of persons)


                        if we could load the persons (with the task list already initalized - maybe using a fetch join), wouldn't that have a better performance and be more elegant?



                        <h:dataTable id="personList" var="person" value="#{personEntityQuery.resultList}">
                        
                          <h:column>#display some person data: #{person.Name}<h:column>
                        
                          <h:column>
                            <h:dataTable id="personTaskList" var="task" value="#{person.tasks)}">   
                              
                              #{task.Name}
                        
                            </h:dataTable>
                          </h:column>
                        
                        </h:dataTable>



                        does anyone know an example for such a situation?

                        • 9. Re: Which component for a sortable list?

                          RichFaces has one too:
                          Link to Demo


                          -mp

                          • 10. Re: Which component for a sortable list?
                            brachie

                            Marcus Popetz wrote on Mar 12, 2008 08:36 PM:


                            RichFaces has one too:
                            Link to Demo

                            -mp


                            Hi,


                            to be honest, in my opinion the Richfaces scrollable datatable is unuseable in production. It has many bugs like disappearing headers after ajax rerendering, or when you try to sort a date column with null dates you get an exception. Besides there is bunch of javascript to load for this component which increases page size.


                            In our project we are mainly using Trinidad's datatable, which has sorting and paging (ajax based) out of the box. In addition Pete implemented this sorting and paging database backed for entityQueries with Trinidad's datatable (seamdiscs example).


                            Alexander

                            • 11. Re: Which component for a sortable list?
                              brachie

                              Pete Muir wrote on Mar 12, 2008 01:32 PM:



                              Alexander Seitz wrote on Mar 12, 2008 12:22 PM:


                              I ask, because in our application we use this type of tables very often. It would be a pain to write an EntityQuery for each associated object collection. Are there other possibilities with less overhead?



                              The minimum is 1 line of xml needed per entity query - you want less than that?


                              Hi,


                              ok, if you define the entityQueries in the components.xml the overhead is less than e.g. defining factory methods.
                              In general I would like to use the benefit of Hibernate to access the collection using the object path like person.tasks.
                              Unfortunately the view does not know how this collection was created, so database backing for sorting or paging is not possible without defining the entityQueries... :(


                              Alexander

                              • 12. Re: Which component for a sortable list?
                                pmuir

                                Martin Trummer wrote on Mar 12, 2008 04:52 PM:


                                so you suggest to have onen parent table iterating over some PersonEnityQuery and for each Person you would call the PersonTaskEntityQuery, like that?




                                No. In this situation I would prepare the data in the backing bean before outputing to the page. This, IMO, correctly separates the concerns of the presentation layer from accessing data.

                                • 13. Re: Which component for a sortable list?
                                  sandman202

                                  I tried using ICEFaces and had a few problems. Their datatable is sortable and has a paginator. The problem lies when you have 2 screens with a datatable. When there are links on the first datable to show the second screen, the page crashes due to the paginator. It was one of several reasons I switched to Richfaces.


                                  Alexander, are you using Richfaces with Trinidad or just Trinidad?


                                  Scott

                                  • 14. Re: Which component for a sortable list?
                                    nickarls

                                    You don't happen to remember what the exception with the ICEFaces paginator was? I've seen stuff with duplicate ID:s for one of the facets in the paginator.

                                    1 2 Previous Next