7 Replies Latest reply on Jul 11, 2006 5:58 PM by bfo81

    dataTable with method execution per row

    trouby

      Hey,

      I have a dataTable of 'user' objects which iterate thorugh a list, i.e:

      <t:dataTable id="rolesDataTableList"
       var="user"
       value="#{userList}"
       rows="10"
       >
       <h:column>
       <f:facet name="header">
       <h:outputText value="#{msgs.id}" />
       </f:facet>
       <h:outputText value="#{user.userId}" />
       </h:column>
      
       <h:column>
       <f:facet name="header">
       <h:outputText value="STATUS" />
       </f:facet>
       ***CALL SOME METHOD AND RETRIEVE STATUS ON THE FLY PER USER ROW**
       </h:column>
       </t:dataTable>
      



      I'd like per user row on a column tag to execute a method and retrieve the status of the user, but since JSF/Seam limitations(or am I wrong?), I can't pass parameters to methods and execute them while the datatable is rendered...

      note: the 'status' cannot be just a property of the 'user' entity since the method requires DB access(and more) and must reside in an EJB entity....


      Any way to solve this?

      Thanks,
      Asaf.

        • 1. Re: dataTable with method execution per row
          paradigmza

          Hey,

          I am not quite sure why


          note: the 'status' cannot be just a property of the 'user' entity since the method requires DB access(and more) and must reside in an EJB entity....


          and this is the way I would do it
          public class User {
           private Integer userid;
           private String status;
          
           ...getters and setters...
          }
          



          @Stateful()
          @Name("somename")
          @Scope(ScopeType.SESSION) //or whatever
          public class UserBean implements UserInterface {
          
           @DataModel
           List<User> userList;
          
           @DataModelSelection
           User selectedUser;
          
           @PersistenceContext
           EntityManager em;
          
           public String doSearch() {
           updateUserList();
          
           return "userlistpage";
           }
          
           private void updateUserList() {
           Query query = em.createNamedQuery(....)
           result = ...connect to databases...
           ...and more ;-) ...
           userList = result
           }
          





          • 2. Re: dataTable with method execution per row
            pmuir

            You could always preprocess the list.

            Mark the status field in the user Entity @Transient (so that it isn't persisted by the container). In updateUserList() iterate over the list created by the database query setting status as you go (here you could interogate other entites, SOAP, whatever).

            • 3. Re: dataTable with method execution per row

              You may also be able to write a JSF EL function. However I think I Pete's method of just getting status along with the original data better.

              • 4. Re: dataTable with method execution per row

                I do preprocessing of lists with @Transient. It works quite well. I also use maps that I add extra objects to to hande the case where some of then are not persisted and I add an empty one under a different key in the map if there is none found.

                • 5. Re: dataTable with method execution per row
                  gavin.king

                   

                  "trouby" wrote:
                  but since JSF/Seam limitations(or am I wrong?), I can't pass parameters to methods and execute them


                  This is a limitation of JSTL-EL. In our experimental JSF fork, Stan has actually implemented method parameter support, but note that we have no current plans to productize this work.

                  • 6. Re: dataTable with method execution per row
                    trouby

                    Cool, but thanks,

                    I'll stick with the @Transient pre-loaded data options for now...

                    • 7. Re: dataTable with method execution per row
                      bfo81

                      I'm not sure if I understood your problem. But this reminds me of a list of entities in which I wanted to show the amount of relations to other entities (just like e.g. users and his posts in this forum). So I put the following into the user entity:

                      @Formula("(select count(*) from Post p where p.user_id = id)")
                      private int postcount;
                      
                      //+ getter + setter

                      The query for the postcount var is being executed on the fly for every user in this example. Maybe you can adapt this proceeding for your purposes.