4 Replies Latest reply on Jun 15, 2007 9:33 AM by Miloslav Vlach

    Session scoped component and usage

    Miloslav Vlach Novice

      Hi all,

      i have problem with SESSION scoped component.

      I have an action which create one entity and add children to it. Name of the entity is ComponentLayout and I would like to this component exits until the save method is invoked.

      But problem is: when I call the action addArticle and add article to the ComponentLayout the collection contains only one item.

      The instance of the ComponentLayout is destroyed and new instance is created.

      Can somebody help me ?

      Thanks Mila

      @Name("componentLayoutAddAction")
      @Scope(ScopeType.SESSION)
      public class ComponentLayoutAddAction implements Serializable{
      
       /**
       *
       */
       private static final long serialVersionUID = 3749007088722731841L;
      
       @In
       Session ses;
      
       @Logger
       Log log;
      
       @DataModel
       List<ArticleLinker> articlesInComponent;
      
       @In(required = false)
       ViewArticle viewArticle;
      
       @In(required = false)
       ArticleLinker articleLinker;
      
       @In
       ComponentLayout componentLayout;
      
       @SuppressWarnings("unchecked")
       @Factory("articlesInComponent")
       public void init() {
       if (componentLayout == null)
       return;
       if (componentLayout.getArticles().size() > 0) {
       articlesInComponent = componentLayout.getArticles();
       }
      
       }
      
       public String addArticle() {
       log.info("adding article: #0", articleLinker);
      
       componentLayout.getArticles().add(articleLinker);
      
       articlesInComponent = null;
       return "success";
       }
      
       public String save() {
       log.info("saving component: #0", componentLayout);
       return "success";
       }
      
       public String remove() {
       log.info("removing article: #0", viewArticle);
       return "success";
       }
      
       @Destroy
       @Remove
       public void end() {
      
       }
      }