a4j:keepAlive doesn't work as expected
medi84 May 4, 2009 4:27 AMI'm trying to test a4j:keepAlive tag. I have three simple .jsp files: test1.jsp, test2.jsp, test3.jsp. All of them have buttons test1, test2, test3, which let me navigate to the next page in order:
test1.jsp -> test2.jsp -> test3.jsp -> test1.jsp -> ... etc.
Here are those .jsp files:
test1.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%> <%@taglib prefix="f" uri="http://java.sun.com/jsf/core" %> <%@taglib prefix="h" uri="http://java.sun.com/jsf/html" %> <f:view> <h:form> <h:inputText value="#{test.testValue}" /> <!-- staticly navigate to test2.jsp --> <h:commandButton value="test1" action="test1" /> </h:form> </f:view>
test2.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%> <%@taglib prefix="f" uri="http://java.sun.com/jsf/core" %> <%@taglib prefix="h" uri="http://java.sun.com/jsf/html" %> <f:view> <h:form> <h:outputText value="#{test.testValue}" /> <!-- staticly navigate to test3.jsp --> <h:commandButton value="test2" action="test2" /> </h:form> </f:view>
test3.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%> <%@taglib prefix="f" uri="http://java.sun.com/jsf/core" %> <%@taglib prefix="h" uri="http://java.sun.com/jsf/html" %> <f:view> <h:form> <h:outputText value="#{test.testValue}" /> <!-- staticly navigate to test1.jsp --> <h:commandButton value="test3" action="test3" /> </h:form> </f:view>
This way I'm testing on which pages is managed bean value #{test.testValue}, which I entered on test1.jsp, available. 'test' is a managed bean defined in faces-config.xml, with request scope.
faces-config:
<navigation-rule> <navigation-case> <from-action>test1</from-action> <to-view-id>/test2.jsf</to-view-id> </navigation-case> </navigation-rule> <navigation-rule> <navigation-case> <from-action>test2</from-action> <to-view-id>/test3.jsf</to-view-id> </navigation-case> </navigation-rule> <navigation-rule> <navigation-case> <from-action>test3</from-action> <to-view-id>/test1.jsf</to-view-id> </navigation-case> </navigation-rule> <managed-bean> <managed-bean-name>test</managed-bean-name> <managed-bean-class>test.Test</managed-bean-class> <managed-bean-scope>request</managed-bean-scope> </managed-bean>
Situations which confuse me are:
1) When I put @KeepAlive annotation on 'test' managed bean, bean behaves like a JSF session bean. I do not need to put any <a4j:keepAlive> tags (and I don't), because it is always available. The value entered in test1.jsp, prints on test2.jsp, test3.jsp, and on test1.jsp back again. I don't understand this kind of redundancy with @KeepAlive, when the same funcionality can be achieved with JSF session scope?!
This led me to conclusion that I shoudn't use @KeepAlive annotation, because this functionality is not what I want. What I want is, to save bean state only on those pages on which I want ...
2) When I remove @KeepAlive annotation from 'test' managed bean, and try to put <a4j:keepAlive> tag on test1.jsp only, or on all three pages, nothing gets saved, it behaves like a regular JSF request scope bean.
RichFaces documentation says nothing about this, forums and google also. Now, I really don't know what kind of functionality I can expect from a4j:keepAlive, when it behaves like a regular request and session scoped managed beans, and when I don't see any change in behaviour when I use/not use <a4j:keepAlive> tag?