0 Replies Latest reply on Aug 5, 2011 2:25 PM by Franek Jop

    ViewScoped problem

    Franek Jop Newbie

      I have simple jsf page with form:

       

      <h:form>

         <h:commandButton value="test" action="#{jsfTest.doit}" >

         </h:commandButton>

      </h:form>

       

      With viewScoped class:

      //////////////////

      @Named(value="jsfTest")

      @ViewScoped

      public class JsfTest {

       

       

                public JsfTest() {

                               System.out.println("New");

                }

        public String doit(){

                               System.out.println("doit");

                               FacesContext ctx = FacesContext.getCurrentInstance();

                               UIViewRoot root = ctx.getViewRoot();

                               System.out.println("uiviewRoot: "+root.toString());

                               return null;

                }

      }

      ////////////////////

      And every time i click the button new UIViewRoot and my JsfTest is created:

      20:18:51,455 INFO  [stdout] (http--127.0.0.1-8080-1) New

      20:18:51,457 INFO  [stdout] (http--127.0.0.1-8080-1) doit

      20:18:51,457 INFO  [stdout] (http--127.0.0.1-8080-1) uiviewRoot: javax.faces.component.UIViewRoot@11b1e39

      20:18:56,548 INFO  [stdout] (http--127.0.0.1-8080-1) New

      20:18:56,548 INFO  [stdout] (http--127.0.0.1-8080-1) doit

      20:18:56,549 INFO  [stdout] (http--127.0.0.1-8080-1) uiviewRoot: javax.faces.component.UIViewRoot@5b56c4

       

      But JsfTest class is ViewScoped. It shoud stay the same at postback to the same page.

       

      I cant figure out where is the problem.