5 Replies Latest reply on Sep 8, 2011 9:36 AM by el_dambro

    jsf - reinit a session bean - managed bean lifecycle problem

    diabolique

      Hi,

       

      I've a (serious) problem developing jsf portlet with:

      -jsf 1.2 portlet

      -gatein 3.1

      -richfaces 3.3.3

      -portlet bridge 2.1 final

       

      This is my scenario:

      -an xhtml page with a session backing bean

      -I would to reinitialize this session bean at page reload/refresh (in particular: when this isn't a postback). I can reinizialize the bean (in the sessionMap) after an action, but at page load (for example when I came from another page url and click on the link on the menu)?

       

      I've try with:

      • rich faces @keepalive on a request managed bean: the bean became a simple SESSION bean (at page reload/refresh it isn't reinitiated)
      • tomahawk (myfaces plugin) <t:saveState bean="myRequestBean">, request bean: the plugin is registered, but the bean is a simple request bean (reinit for all action)
      • jsf webui extension (AbstractPageBean with init()/prerender()/preprocess() methods): problem is in this post  http://community.jboss.org/message/598888#598888

       

       

      Help me! HOW CAN I REINIT A SESSION BEAN at page refresh/reload?

        • 1. jsf - reinit a session bean - managed bean lifecycle problem
          diabolique

          any help??

          • 2. jsf - reinit a session bean - managed bean lifecycle problem
            wesleyhales

            Try using a seam page action (example here)

             

            <page view-id="/home.xhtml">

                     <action execute="#{identity.login}" if="#{identity.loggedIn}"/>

                    <navigation from-action="#{identity.login}">

                        <render  view-id="/main.xhtml"/>

                    </navigation>

            ....

            • 3. jsf - reinit a session bean - managed bean lifecycle problem
              diabolique

              Hi, thanks for the reply.

               

              I don't use seam in my project. So, how seam reinit the bean with your code? I don't understand.

               

              Is it similar to faces-config.xml!

              • 4. jsf - reinit a session bean - managed bean lifecycle problem
                diabolique

                This is my workaround:

                 

                -in every xhtml page (portlet1 has an initial page page1, portlet2 has an initial page page2,...) I've add an <h:outputText value="{Portlet1JSFBean.clean}">

                -in Portlet1JSFBean, Portlet2JSFBean,... "clean" is a simple String variable

                -in the getter method I've add some custom code:

                public String getClean() {

                  if (<httpSession>.getAttribute(PORTLET_ALIVE) != null && !<httpSession>.getAttribute(.PORTLET_ALIVE).equals(SESSION_BEAN_PORTLET1))

                  //cleanJsfSession

                FacesContext.getCurrentInstance().getExternalContext().getSessionMap().remove(SESSION_BEAN_PORTLET1_NAME); 

                return clean;

                  }

                 

                -in every constructor of jsf beans:

                <httpSession>.setAttribute(PORTLET_ALIVE, SESSION_BEAN_PORTLET1_NAME);

                 

                 

                In this way, every portlet/jsfBean says: "I'm the current portlet alive", and when I change the portal page (see another portlet), getClean() reinizialize the current session bean.

                 

                 

                @keepalive  (richfaces) instead, is ok for a page bean, but only for navigation in the specific portlet. If you change the portal page, the jsf bean (session, request, or page is the same) isn't reinizialized.

                 

                 

                Is ok ?

                 

                 

                Thanks

                • 5. Re: jsf - reinit a session bean - managed bean lifecycle problem
                  el_dambro

                  Yes I think it's ok! With some adjustments for referers and refreshes of the page it will work!