Author: SergeySmirnov
Date: 2007-08-01 19:59:53 -0400 (Wed, 01 Aug 2007)
New Revision: 1995
Modified:
trunk/samples/richfaces-demo/src/main/webapp/richfaces/keepAlive/usage.xhtml
Log:
keepAlive
Modified: trunk/samples/richfaces-demo/src/main/webapp/richfaces/keepAlive/usage.xhtml
===================================================================
---
trunk/samples/richfaces-demo/src/main/webapp/richfaces/keepAlive/usage.xhtml 2007-08-01
23:28:02 UTC (rev 1994)
+++
trunk/samples/richfaces-demo/src/main/webapp/richfaces/keepAlive/usage.xhtml 2007-08-01
23:59:53 UTC (rev 1995)
@@ -7,6 +7,12 @@
xmlns:rich="http://richfaces.ajax4jsf.org/rich">
<ui:composition template="/templates/component-sample.xhtml">
<ui:define name="sample">
+ <style type="text/css">
+ .pcolumn {
+ padding:10px;
+ vertical-align:top;
+ }
+ </style>
<p>
a4j:keepAlive extends the live cycle for request scope beans. In general, each Ajax
request works inside the own request scope. Therefore, the state of the component
@@ -32,6 +38,74 @@
will send from this page.
</p>
<div class="sample-container" >
+ <h:panelGrid columns="2" width="100%"
columnClasses="pcolumn">
+
+ <f:verbatim>
+ This example will not work properly. The expression for 'enabled'
attribute
+ equals true only after UPDATE model phase when the rsBean properties are
+ updated with submitted values. So, the component is rendered as enabled
+ on the RENDER RESPONSE phase.<br />
+ However, those values do not make sence during the next Ajax request. The
+ rsBean is created from scratch as soon as it is a new request. JSF makes a
+ decision what is process on the second (APPLY VALUES) phase. At this moment,
+ the expression for 'disabled' still equals false. Therefore, the
processing
+ for button is bypassed. The action does not invoked as a result.
+ phase
+ </f:verbatim>
+
+ <f:verbatim>
+ This example will work like expected. The code is almost the same as for
+ example on the left. Used managed been is based on the same class. The only
+ difference is <b>a4j:keepAlive beanName="rsBean2"</b>. This
statment
+ declares to keep the value of the rsBean2 between the Ajax requests.<br/>
+ The rsBean2 is still a request scope bean as it is defined in the
+ faces-config.xml file. a4j:keepAlive stores the rsBean at the end of the
+ JSF lifecycle. At the beginning of the next cycle, it updates with
+ the rsBean2 with the stored data. Therefore, the expression for 'disabled'
+ equals true on the second phase. The button is processed and the action is
+ invoked.
+ </f:verbatim>
+
+
+ <h:panelGroup>
+ <h:form>
+ <h:inputText size="4" label="First Addent"
value="#{rsBean.addent1}">
+ <a4j:support event="onkeyup" reRender="btn" />
+ </h:inputText>
+ <h:outputText value="+"/>
+ <h:inputText size="4" label="Second Addent"
value="#{rsBean.addent2}">
+ <a4j:support event="onkeyup" reRender="btn" />
+ </h:inputText>
+ <a4j:commandButton style="margin:0 5px" id="btn"
action="#{rsBean.doSum}"
+ value="=" reRender="sum"
+ disabled="#{rsBean.addent1 == null or rsBean.addent2==null}"/>
+ <h:outputText id="sum" value="#{rsBean.sum}" />
+ </h:form>
+ </h:panelGroup>
+
+ <h:panelGroup>
+ <a4j:keepAlive beanName="rsBean2" />
+ <h:form>
+ <h:inputText size="4" label="First Addent"
value="#{rsBean2.addent1}">
+ <a4j:support event="onkeyup" reRender="btn2" />
+ </h:inputText>
+ <h:outputText value="+"/>
+ <h:inputText size="4" label="Second Addent"
value="#{rsBean2.addent2}">
+ <a4j:support event="onkeyup" reRender="btn2" />
+ </h:inputText>
+ <a4j:commandButton style="margin:0 5px" id="btn2"
action="#{rsBean2.doSum}"
+ value="=" reRender="sum2"
+ disabled="#{rsBean2.addent1 == null or rsBean2.addent2==null}"/>
+ <h:outputText id="sum2" value="#{rsBean2.sum}" />
+ </h:form>
+ <a4j:outputPanel ajaxRendered="true">
+ <h:messages />
+ </a4j:outputPanel>
+ </h:panelGroup>
+
+
+
+ </h:panelGrid>
</div>
</ui:define>
<ui:define name="sources">