0 Replies Latest reply on Mar 9, 2012 11:32 AM by Ivan Costa

    Migrating from Richfaces 3.3.3 to 4.2 - problem with @KeepAlive - @ViewScoped

    Ivan Costa Newbie

      Hi all,

       

      I'm migrating from  Richfaces 3.3.3 to 4.2 and I'm getting trouble with @ViewScoped.

       

      On RF 3.3.3 it was fine for me to navigate from pageA.xhtml (list of entities) to pageB.xhtml (edit the entity) this way:

       

      beanA

           @KeepAlive

       

      pageA.xhtml

           on a datatable rowclick event, a jsFunction calls a method on beanB do get the id, populate beanB values, and return pageB.xhtml, like this:

       

           <a4j:jsFunction name="jsFooName" action="#{beanB.edit}">

                <f:param name="id" />

            </a4j:jsFunction>

       

           <rich:datatable value="#{beanA.someList}"

                var="item"

                onRowClick="jsFooName('#{item.id}');"

       

      beanB

           @KeepAlive

       

           public String edit() {

                // get id in the request

                // read from database and populate beanB properties

                return "pageB.xhtml"

           }

       

      It was fine, but NOW, changing from @KeepAlive to @ViewScoped, pageB.xhtml DO NOT show any values, just empty fields AND I need to click twice on a commandButton on pageB.xhtml to get back to pageA.xhtml (first click just blinks the page)

       

           pageB.xhtml

                <h:commandButton value="Back" action="#{beanA.backMethod}" immediate="true" />

       

      So, I had two problems:

      1) data are not shown in pageB.xhtml

      2) commandButton needs to be clicked twice to get back from pageB to pageA

       

      Then, I've tried to use a @PostConstruct method to populate the page, and changed the calling

      from:

           <a4j:jsFunction name="jsFooName" action="#{beanB.edit}">

                <f:param name="id" />

            </a4j:jsFunction>

       

      to:

           <a4j:jsFunction name="jsFooName" action="pageB.xhtml">

                <f:param name="id" />

            </a4j:jsFunction>

       

      wich solved problem both problems...

      What's wrong with my old approach? Is calling beanB.method on a pageA.xhtml and beanA.method on pageB  (a type of cross calling) wrong with @ViewScoped ?

       

      Thanks in advance

      Ivan