JBoss.orgCommunity Documentation
Table 6.3. a4j : keepAlive attributes
Attribute Name | Description |
---|---|
ajaxOnly | if true, bean value restored in ajax requests only. |
beanName | name of bean for EL-expressions. |
Table 6.4. Tag identification parameters
Name | Value |
---|---|
component-type | org.ajax4jsf.components.KeepAlive |
component-family | org.ajax4jsf.components.AjaxKeepAlive |
component-class | org.ajax4jsf.components.AjaxKeepAlive |
To create the simplest variant on a page use the following syntax:
Example:
<a4j:keepAlive beanName = "testBean"/>
Note, that to be put into the request scope the pointed bean should be registered inside faces-config.xml file and marked with org.ajax4jsf.model.KeepAlive annotation.
A bean instance in the request scope could also be saved directly through the declaration of @KeepAlive
annotation inside the bean.
If a managed bean is declared with request scope in the configuration file with the help of <managed-bean-scope> tag then the life-time of this bean instance is valid only for the current request. Any attempts to make a reference to the bean instance after the request end will throw in Illegal Argument Exception by the server. To avoid these kinds of Exception, component <a4j:keepAlive> is used to maintain the state of the whole bean object among subsequent request.
Example:
<a4j:keepAlive beanName = "#{myClass.testBean}"/>
The "beanName" attribute defines the request scope bean name you'd like to re-use. Note that this attribute must point to a legal JSF EL expression which resolves to a managed mean instance. For example for the above code the class definition may look like this one:
class MyClass{
...
private TestBean testBean;
// Getters and Setters for testBean.
...
}
The "ajaxOnly" attribute declares whether the value of the bean should be available during a non-Ajax request. If the value of this attribute is "true" a request scope bean keeps the same value during Ajax requests from the given page. If a non-Ajax request is sent from this page the bean is re-created as a regular request scope bean.
On the component LiveDemo page you can see the example of <a4j:keepAlive> usage and sources for the given example.
Some additional information about usage of component can be found on theAjax4JSF Users Forum.