9 Replies Latest reply on Apr 25, 2006 3:38 AM by kh2ouija

    Simple Seam Question...

    edwar64896

      Hi.

      I am a newbie at Seam so please forgive what might seem to be an obvious question...

      I'm trying to implement some hierarchy navigation screens. Code is posted below:

      home.xhtml
      ...
       <div class="chierarchy">
       <h:dataTable value="#{categories}" var="cat">
       <h:column>
       <h:commandLink value="#{cat.name}" action="#{catList.select}" />
       </h:column>
       </h:dataTable>
       </div>
      ...
      


      CategoryListBean.java
      ...
      @Stateful
      @Scope(SESSION)
      @Name("catList")
      @Interceptors(SeamInterceptor.class)
      public class CategoryListBean implements java.io.Serializable, CategoryList {
      
       @DataModel
       private List<Category> categories;
      
       @Out(required=false)
       @DataModelSelection
       private Category category;
      
       @PersistenceContext(type=EXTENDED)
       private EntityManager em;
      
       @Factory("categories")
       public void findCategoryList() {
       long catId=1;
       try {
       catId=category.getCategoryId();
       } catch (Exception e) {}
       System.out.println(catId);
       categories = em.createQuery("from Category where parent_id = :parid")
       .setParameter("parid",catId)
       .getResultList();
       }
      
       public String select() {
       return "selected";
       }
      
       public String delete() {
       return "deleted";
       }
      
       @Remove @Destroy
       public void destroy () {}
      
      }
      ...
      


      Category.java
      ...
      @Entity
      @Name("category")
      public class Category implements java.io.Serializable {
      
       private long categoryId;
       private Collection<Asset> asset;
       private Collection<Category> children;
       private Category parent;
       private String name;
      
       public Category() {}
      ...
       /**
       * Get children.
       *
       * @return children as String.
       */
       @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER, mappedBy="parent")
       public Collection<Category> getChildren()
       {
       return children;
       }
      ...
      
      


      When a dataTable entry is selected in the browser, I am assuming that the selected "Category" will be passed in as the @DataModelSelection attribute and that the next time the table is rendered, the parent cateory will have changed. Unfortunately, this doesn't happen. I don't seem to get the expected behaviour and the page re-renders as before. Seeing as this is such a trivial problem, I would be grateful if someone could set me straight here.

      Thanks.

      Mark


        • 1. Re: Simple Seam Question...
          dr_j

          I'm having very much the same problem, with code that is much like what you have. I've searched the forums, and apparently it's not that uncommon a problem, but unfortunately, there aren't responses to many of them.

          If you've found a solution, please please please let me know.


          Thanks!

          j

          • 2. Re: Simple Seam Question...
            dr_j

            Okay, I actually made some progress. My issue appears to be that in my action of the commandLink, I'm using a transition via jPDL (action="next") in order to flow to the next page. In that case, my @ModelSelection is not being updated.

            If I create a dummy method, public String select() and make sure that my commandLink invokes that, then the model selection IS being updated .... but I lose my navigation to the next page (of course).


            Ideas? Suggestions?

            j

            • 3. Re: Simple Seam Question...
              gavin.king

              The selection will only be initialized if you call the component during the request that originates from the list page.

              • 4. Re: Simple Seam Question...
                kh2ouija

                I had a similar issue, check here. It was because of a redirect tag in the navigation rule.

                To my knowledge, the factory method only runs if the datamodel is null. So, even if you change the parent, the datamodel will not be updated automatically.

                • 5. Re: Simple Seam Question...
                  gavin.king

                   

                  "kh2ouija" wrote:
                  To my knowledge, the factory method only runs if the datamodel is null. So, even if you change the parent, the datamodel will not be updated automatically.


                  Right, if you want a method that runs every time, use @Unwrap instead.

                  • 6. Re: Simple Seam Question...
                    kh2ouija

                     

                    "gavin.king@jboss.com" wrote:

                    Right, if you want a method that runs every time, use @Unwrap instead.


                    I haven't managed to make @Unwrap work yet, I know, must be something silly. My code looks like this:

                    @DataModel
                    private List<Subscription> subscriptions;
                    
                    @Unwrap
                    public List<Subscription> getSubscriptions() {
                     subscriptions = subscriptionDAO.getSubscriptions();
                    }
                    


                    And in the page I reference it as #{subscriptions}. I'm obviously doing something wrong, as the Unwrap method is never executed. Before, I had it annotated as Factory and it worked ok, but I need that list to be refreshed all the time, not just initialized once. Could you tell me what's wrong in what I'm doing?

                    • 7. Re: Simple Seam Question...
                      kh2ouija

                      Sorry, bad c/p in the previous post, I skipped the return line. It looks like this:

                      @DataModel
                      private List<Subscription> subscriptions;
                      
                      @Unwrap
                      public List<Subscription> getSubscriptions() {
                       subscriptions = subscriptionDAO.getSubscriptions();
                       return subscriptions;
                      }
                      


                      • 8. Re: Simple Seam Question...
                        gavin.king

                        That is how you use @Factory, not @Unwrap.

                        • 9. Re: Simple Seam Question...
                          kh2ouija

                          Can you please explain how to use @Unwrap to have my datamodel refreshed each time? I haven't found this in any example/doc. Thanks.