3 Replies Latest reply on Jul 19, 2010 5:27 AM by jethroborsje.j.borsje.dji.minjus.nl

    POJO component inheritance

    jethroborsje.j.borsje.dji.minjus.nl

      I want to use inheritance with my POJO Seam component in order to abstract all functionality common to all wizard controller in my application.


      I have an abstract class called AbstractWizardController and an implementation class called ConcereteWizardController. The abstract class does not have @Name and @Scope annotations, but it does have @Create and @End annoations on several methods.


      When I refer to the component from my JSF page it somehow gets created twice. The first time the method annotated with @Create is not called, the second time it is. Am I trying to do something which is not supported?

        • 1. Re: POJO component inheritance
          kragoth

          Can you provide the code please.

          • 2. Re: POJO component inheritance
            jethroborsje.j.borsje.dji.minjus.nl

            I managed to narrow down my problem to the following issue: the subclass (the one with the @Name and @Scope annotations) keeps the values of its variables across the long running conversation, but the variables of the superclass are forgotten.


            This is a snippet of my code:


            public abstract class AbstractWizardController
            {
                    private Stack<String> pages;
            
                    protedted void init()
                    {
                            pages = new Stack<String();
                    }
            
                    public void doStuff()
                    {
                            LOG.debug(pages);
                    }
            }
            
            @Name("myWizardController")
            @Scope(ScopeType.CONVERSATION)
            public class WizardControllerImpl extends AbstractController
            {
                    public String myValue;
            
                    @Create
                    @Begin
                    public void init()
                    {
                            super.init();
                            myValue = "test";
                    }
            
                    public void doOtherStuff()
                    {
                            // Do other stuff here.
                            LOG.debug(myValue);
                    }
            }



            Each time I move from one page to another the doStuff() method gets called. The first time the pages Stack is an empty stack. When I move to another page the pages variable is null all of a sudden.

            • 3. Re: POJO component inheritance
              jethroborsje.j.borsje.dji.minjus.nl

              I recently found the solution to this problem:
              1 - use getters and setters everywhere instead of referencing a class variable directly.
              2 - do NOT make the getter and setter methods final.