3 Replies Latest reply on Jul 16, 2009 6:13 PM by alexsmirnov

    DataTable Rendering

    israel.bgf

      Can a datatable be rendered or not based on it value attribute, but without referencing it directly? Example:

      <rich:dataTable value="#{database.getResultList()}" rendered="#{this.datatable.notEmpty}"/>

      The problem is, i cant have a list in a backing bean to get this values, i need to access them directly, but this way i cant get a "size" value, to point in the rendered expression.

      Any idea?

      Thks in advance and keep up the good work richfaces team!

        • 1. Re: DataTable Rendering
          ilya_shaikovsky

          rendered="#{not empty database.resultList}". It will call your getter.

          • 2. Re: DataTable Rendering
            israel.bgf

             

            "ilya_shaikovsky" wrote:
            rendered="#{not empty database.resultList}". It will call your getter.


            But that's the problem Ilya, the getResultList is a method that perform a database search (i'm using Seam and its Jboss EL), and if i use the getResultList() i will perform another database hit and that's not good. So that's why i'm asking for an internal mechanism of the datatable to be rendered only if its value is not empty.

            Or should i really create a list in the backingbean to this purpose?

            Example:

            -- Method
            
            public List<Thing> getResultList(){
             return em.createEntityManager("from Stuff").getResultList();
            }
            
            -- Facelets
            
            <rich:dataTable value="#{backingbean.getResultList()}" rendered="#{backingbean.getResultList().size()}">
            ...
            <!-- Bad thing, two database hits to do the same thing -->
            <!-- Is the only way save the search result in a backing bean list, to get it size after? -->
            


            Thks again!

            • 3. Re: DataTable Rendering
              alexsmirnov

              You can use Seam outjection to keep search result during request and avoid multiply database calls. Keep in mind, UIData component could call value attribute for each JSF lifecycle phase.