<bean> element

Appears in: <component-specification> and <page-specification>

A <bean> is used to add behaviors to a page or component via aggregation. Each <bean> defines a named JavaBean that is instantiated on demand. Beans are accessed through the OGNL expression beans.name.

Once a bean is instantiated and initialized, it will be retained by the page or component for some period of time, specified by the bean's lifecycle.

bean lifecycle

none

The bean is not retained, a new bean will be created on each access.

page

The bean is retained for the lifecycle of the page itself.

render

The bean is retained until the current render operation completes. This will discard the bean when a page or form finishes rewinding.

request

The bean is retained until the end of the current request.

Caution should be taken when using lifeycle page. A bean is associated with a particular instance of a page within a particular JVM. Consecutive requests may be processed using different instances of the page, possibly in different JVMs (if the application is operating in a clustered environment). No state particular to a single client session should be stored in a page.

Beans must be public classes with a default (no arguments) constructor. Properties of the bean may be configured using the <set-property> and <set-message-property> elements.

Figure C.3. <bean> Attributes

NameTypeRequired ?Default ValueDescription
namestringyes The name of the bean, which must be a valid Java identifier.
classstringyes The name of the class to instantiate.
lifecyclenone|page|render|requestnorequestAs described above; duration that bean is retained.

Figure C.4. <bean> Elements