2 Replies Latest reply on Aug 10, 2006 9:16 AM by urswag

    Synchronizing to DataModels

    urswag

      I need a mechanism to synchronize the inner dataTable with the outer one.


      <h:dataTable var="assort" value="#{assortments}">
      <h:column>
      <h:outputLink value="">
      <h:outputText value="#{assort.description}" />
      </h:outputLink>
      <h:dataTable var="category" value="#{assortmentCategories}">
      <h:column>
      <h:outputLink value="">
      <h:outputText value="#{category.description}" />
      </h:outputLink>
      </h:column>
      </h:dataTable>
      </h:column>
      </h:dataTable> <br />



      The list assortmentCategories is depended from the current element in the assortments list. I need a mechanism to update it.

      Assortment Session Bean code part



      @DataModel
      private List<Assortment> assortments;

      ....

      @Factory("assortments")
      public void findAssortments() {

      .....
      }



      AssortmentCategory Session Bean code part



      @DataModel
      private List<Category> assortmentCategories;

      ....

      @Factory("assortmentCategories")
      public void findCategories() {

      ....
      }






        • 1. Re: Synchronizing to DataModels
          bfo81

          I'm not sure what you mean exactly. Please give me an example :).

          • 2. Re: Synchronizing to DataModels
            urswag

            I have two stateless session beans assortmentManager and categoryManager. Category is a detail bean of Assortment (1:N relation).
            In the inner data table the assortmentCategories list must always built up because the reference assortmemt always changes.

            Remember the JSF code



            <h:dataTable var="assort" value="#{assortments}">
            <h:column>
            <h:outputLink value="">
            <h:outputText value="#{assort.description}" />
            </h:outputLink>
            <h:dataTable var="category" value="#{assortmentCategories}">
            <h:column>
            <h:outputLink value="">
            <h:outputText value="#{category.description}" />
            </h:outputLink>
            </h:column>
            </h:dataTable>
            </h:column>
            </h:dataTable>



            The code of the both session beans. I need a synchronize mechanism for the list assortmentCategories of the inner data table.



            package ...;

            import ....;

            @Stateless
            @Scope(SESSION)
            @Name("assortmentManager")
            @Interceptors(SeamInterceptor.class)
            public class AssortmentManagerBean implements Serializable, AssortmentManager {

            @DataModel
            private List<Assortment> assortments;

            @PersistenceContext
            private EntityManager em;

            @Factory("assortments")
            public void findAssortments() {

            assortments = em.createQuery("from Assortment a order by a.description")
            .getResultList();

            }

            @Remove
            @Destroy
            public void destroy() {

            }

            }



            The other bean



            package ....;

            import ...;

            @Stateless
            @Scope(SESSION)
            @Name("categoryManager")
            @Interceptors(SeamInterceptor.class)
            public class CategoryManagerBean implements Serializable,
            CategoryManager {

            @DataModel
            private List<Category> assortmentCategories;

            @PersistenceContext
            private EntityManager em;

            @Factory("assortmentCategories")
            public void findCategories() {

            Query query = em
            .createQuery("from Category c where c.assortment = :assortment");
            query.setParameter("assortment", assortment);
            assortmentCategories = query.getResultList();

            }

            @Remove
            @Destroy
            public void destroy() {

            }