2 Replies Latest reply on Oct 1, 2010 4:30 PM by cubrovicd

    how to avoid serialization

    cubrovicd

      How to avoid serialization and recreation of my components from AjaxStateManager.

       

       

      I have createt html form simple as

       

      <h:messages globalOnly="true" styleClass="message" />
      <h:form>
      <rich:panel binding="#{formmain.frame}" id="mainframeid">

       

      </rich:panel>
      </h:form>

       

      and all of the subpanels ,tabbed panels menus... (richfaces components) are created dynamically in my formmain session scoped bean.

       

      After that all of page actions are executed during ajax (as I said richfaces components) so idea is never to reload that page again (classic reload) but to change it with ajax requests.

       

      Well that parts works well for now but what make problem for me is saving and recreating of components.
      Can I somehow tell to jsf to not saved my component and then creates it from the beggining but to use tha same component model that I stored in formmain.frame all the time.

       

      When components are recreated I cant used references I have stored in my formmain (to tabbedpanel to footer...) so I have to traverse my component tree (formmain.frame children...) to find component I want to removed or add children to.
      This makes things harder and not so clean in code.

       

      I want to make some references from that components to some ejb beans so I wanted this components to be created only once!
      (MyButton that extends ajaxbutton and have references to some ejb bean to execute action on.

       

       

      Futhermore this is stacktrace in case it makes it easier to see wahat happening.

       

      restoreView recreates components by creating my menuitem again on server and that seems ok but what I want it to do is to some how use the menuitem already created and added to #{formmain.frame} panel.

       

      Can I achive that behavior. Am I wrong wanted to have this kind of behavior?

       

      at com.incrementum.framework.form.seam.MenuItem.<init>(MenuItem.java:16)
      02:36:17,675 ERROR [STDERR] at sun.reflect.GeneratedConstructorAccessor167.newInstance(Unknown Source)
      02:36:17,675 ERROR [STDERR] at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      02:36:17,675 ERROR [STDERR] at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
      02:36:17,675 ERROR [STDERR] at java.lang.Class.newInstance0(Class.java:372)
      02:36:17,675 ERROR [STDERR] at java.lang.Class.newInstance(Class.java:325)
      02:36:17,675 ERROR [STDERR] at org.ajax4jsf.application.ComponentsLoaderImpl.createComponent(ComponentsLoaderImpl.java:40)
      02:36:17,675 ERROR [STDERR] at org.ajax4jsf.application.AjaxStateManager$TreeStrutureNode.restore(AjaxStateManager.java:476)
      02:36:17,675 ERROR [STDERR] at org.ajax4jsf.application.AjaxStateManager$TreeStrutureNode.restore(AjaxStateManager.java:490)
      02:36:17,675 ERROR [STDERR] at org.ajax4jsf.application.AjaxStateManager$TreeStrutureNode.restore(AjaxStateManager.java:490)
      02:36:17,675 ERROR [STDERR] at org.ajax4jsf.application.AjaxStateManager$TreeStrutureNode.restore(AjaxStateManager.java:490)
      02:36:17,675 ERROR [STDERR] at org.ajax4jsf.application.AjaxStateManager$TreeStrutureNode.restore(AjaxStateManager.java:490)
      02:36:17,675 ERROR [STDERR] at org.ajax4jsf.application.AjaxStateManager$TreeStrutureNode.restore(AjaxStateManager.java:490)
      02:36:17,675 ERROR [STDERR] at org.ajax4jsf.application.AjaxStateManager.restoreView(AjaxStateManager.java:244)
      02:36:17,675 ERROR [STDERR] at com.sun.faces.application.ViewHandlerImpl.restoreView(ViewHandlerImpl.java:311)
      02:36:17,675 ERROR [STDERR] at org.ajax4jsf.application.ViewHandlerWrapper.restoreView(ViewHandlerWrapper.java:116)
      02:36:17,675 ERROR [STDERR] at org.ajax4jsf.application.AjaxViewHandler.restoreView(AjaxViewHandler.java:159)
      02:36:17,675 ERROR [STDERR] at org.jboss.seam.jsf.SeamViewHandler.restoreView(SeamViewHandler.java:93)
      02:36:17,675 ERROR [STDERR] at com.sun.facelets.FaceletViewHandler.restoreView(FaceletViewHandler.java:316)

       

       

       

       

      I trieed putting following in web.xml. Still same behaviour

       

      <context-param>
      <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
      <param-value>server</param-value>
      </context-param>

       

      <context-param>
      <param-name>org.apache.myfaces.COMPRESS_STATE_IN_SESSION</param-name>
      <param-value>false</param-value>
      </context-param>
      <context-param>
      <param-name>org.apache.myfaces.SERIALIZE_STATE_IN_SESSION</param-name>
      <param-value>false</param-value>
      </context-param>
      <context-param>
      <param-name>org.ajax4jsf.SERIALIZE_SERVER_STATE</param-name>
      <param-value>false</param-value>
      </context-param>
      <context-param>
      <param-name>com.sun.faces.serializeServerState</param-name>
      <param-value>false</param-value>
      </context-param>

       

       

       

      I changed my tabpanel form
      htmlTabPanel.setSwitchType(UISwitchablePanel.AJAX_METHOD);
      to
      htmlTabPanel.setSwitchType(UISwitchablePanel.SERVER_METHOD);

       

      still same stacktrace

       

       

      Any pointers would be highly appreciated.

       

      Danilo

        • 1. Re: how to avoid serialization
          nbelaevski

          Hi Danilo,

           

          I suggest to review approach of creating components wired to value expressions that are using EJB beans + bindings. View state saving is a major point in JSF architecture and many RF components rely on this. BTW, JSF specification highly recommends against usage of session-scoped beans to bind components.

          • 2. Re: how to avoid serialization
            cubrovicd

            Thanks for replying Nick

             

            You're right about JSF specification but for this purpose I found that this kind of binding would be best solution.

            I'm little limited in solutions cause I have to build my webpage on same base like our desktop app.

            View state saving is great technique but not applicable everywhere.

            I think that's why those com.sun.faces.serializeServerState, org.ajax4jsf.SERIALIZE_SERVER_STATE... config parametars exist in the first place.

            But why this parametars dont make no change in jboss seam richfaces application.

            Is this broken or am I using it wrong way. Maybe I missunderstood this parametars somehow. Dont know.

            I saw people using those parametars for similar purposes. They mostly use it for performance boost but anyway that kind of behaviour I need but cant make those parametars to make a difference.