4 Replies Latest reply on May 9, 2011 11:05 AM by Alexandru MG

    a4j:keepAlive - Bean is alive too long

    Paul Baker Apprentice

      I need some help understanding keepAlive.

      I have a number of content pages that are reRendered based on a panelMenu selection. Each content view contains a keepAlive tag for its assocoiated "Controller" bean.

      The problem is that I want to "kill" the Controller bean once a new content view is rendered. But with the current implementation, once keepAlive has been invoked for a bean, the bean is not released. The problem may be that the "page" does not change just the content.

      Is there a way to release a "keepAlive" bean based on a view and not the page?

      Example: the content varies based on the panelMenu selection.

      <html xmlns="http://www.w3.org/1999/xhtml"
       xmlns:ui="http://java.sun.com/jsf/facelets"
       xmlns:h="http://java.sun.com/jsf/html"
       xmlns:rich="http://richfaces.ajax4jsf.org/rich"
       xmlns:a4j="http://richfaces.org/a4j"
       xmlns:c="http://java.sun.com/jstl/core"
       xmlns:f="http://java.sun.com/jsf/core" xml:lang="en" lang="en">
      
       <rich:panel id="contentPage">
       <c:if test="#{ahm565State.selectionPage == 'alnSupplierPage'}">
       <a4j:include viewId="/contentPage/alnSupplierPage.xhtml" />
       </c:if>
      
       <c:if test="#{ahm565State.selectionPage == 'alnCarrierPage'}">
       <a4j:include viewId="/contentPage/alnCarrierPage.xhtml" />
       </c:if>
      
       <c:if test="#{ahm565State.selectionPage == 'alnRevisionsPage'}">
       <a4j:include viewId="/contentPage/alnRevisionsPage.xhtml" />
       </c:if>
      
       <c:if test="#{ahm565State.selectionPage == 'alnEffectiveSheetsPage'}">
       <a4j:include viewId="/contentPage/alnEffectiveSheetsPage.xhtml" />
       </c:if>
      
       <c:if test="#{ahm565State.selectionPage == 'alnDocumentsPage'}">
       <a4j:include viewId="/contentPage/alnDocumentsPage.xhtml" />
       </c:if>
      
       <c:if test="#{ahm565State.selectionPage == 'alnMessagesPage'}">
       <a4j:include viewId="/contentPage/alnMessagesPage.xhtml" />
       </c:if>
      
       </rich:panel>
      </html>


      Each content view start off like this with a keepAlive for the associated controller bean. So, in this case supplierController is kept alive between requests. But if I change the view, I want to "release" supplierController.

      Any ideas?

      <html xmlns="http://www.w3.org/1999/xhtml"
       xmlns:ui="http://java.sun.com/jsf/facelets"
       xmlns:h="http://java.sun.com/jsf/html"
       xmlns:rich="http://richfaces.ajax4jsf.org/rich"
       xmlns:a4j="http://richfaces.org/a4j"
       xmlns:c="http://java.sun.com/jstl/core"
       xmlns:f="http://java.sun.com/jsf/core" xml:lang="en" lang="en">
      
       <body>
       <center>
       <h:outputLabel value="Supplier" styleClass="TitleNormal" />
       </center>
      
       <ui:include src="/messages.xhtml" />
      
       <a4j:keepAlive beanName="supplierController" ajaxOnly="true" />