JBoss.org Community Documentation

- Prev
- Next

## 6.2. < a4j:keepAlive >

### 6.2.1. Description

The <a4j:keepAlive> component allows to keep a state of each bean between requests.

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. Component identification parameters

Name | Value
--- | ---
component-type | org.ajax4jsf.components.KeepAlive
component-family | org.ajax4jsf.components.AjaxKeepAlive
component-class | org.ajax4jsf.components.AjaxKeepAlive

### 6.2.2. Creating the Component with a Page Tag

To create the simplest variant on a page use the following syntax:

Example:

    <a4j:keepAlive beanName = "testBean"/>

### 6.2.3. Creating the Component Dynamically Using Java

Example:

    import org.ajax4jsf.ajax.AjaxKeepAlive;

    ...

    AjaxKeepAlive myKeepAlive = new AjaxKeepAlive();

    ...

### 6.2.4. Key attributes and ways of usage

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}"/>

Note that the attribute "beanName" 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:

            class MyClass{

        ...

        private TestBean testBean;

        // Getters and Setters for testBean.

        ...

    }

### 6.2.5. Relevant resources links

Here 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 here.

- Prev6.1. < a4j:ajaxListener >
- Top of page
- Front page
- Next6.3. < a4j:actionparam >