5 Replies Latest reply on May 4, 2010 9:56 AM by Matthias Wermund

    KeepAlive Behaviour

    Dean Ashby Newbie


      We've been making use of the keepalive facility within RichFaces to maintain state between page refreshes. In the process we have noticed a few subtle points related to how keepalives are implemented that may be useful to the community.

      Keepalives can be applied two ways, as an annotation on the bean or as a tag within the page. The implementation of these two methods is quite different (as of version 3.3.1GA). In the case of the annotation all the implementation is provided in org.ajax4jsf.application.AjaxStateManager, while the tag uses a a combination of the org.ajax4jsf.event.AjaxPhaseListener and a tag or handler class depending on wheter your using JSP or facelets.

      The key difference we noticed was that when using the annotation implementation the state bean is restored prior to phase one (restore view) of the JSF life cycle, whereas when using the tag implementation, the state bean is not restored until immediately after phase one. The latter has implications when injecting the state bean into a backing bean that also has bound components. When the bound component is being restored at phase one, the request scoped backing bean is being constructed, and the DI framework tries to inject the state bean. Because the state bean has not been restored the DI framework constructs a new state bean and injects that - effectively wiping out the state.

      It took us a bit if digging to realise that there were differences in how the keepalive is implemented. We're not sure if this should be considered a bug, it seems like it could be fixed by modifying the tag implementation so that the beans are restored in the beforePhase() method of the AjaxPhaseListener rather than in the afterPhase() method. in the meantime we're sticking to using @keepalive rather than the tag.