The <managed-bean> element declares
a
managed bean, which is created and populated by JSF when
it's needed (e.g., when a value binding expression
referencing it is evaluated) but it doesn't yet
exist in the declared scope.
Syntax
<managed-bean>
[<description [xml:lang="lang"]>description</description>]*
[<display-name [xml:lang="lang"]>displayName</display-name>]*
[<icon [xml:lang="lang"]>
[<small-icon>iconPath</small-icon>]
[<large-icon>iconPath</large-icon>]
</icon>]*
<managed-bean-name>managedBeanName</managed-bean-name>
<managed-bean-class>className</managed-bean-class>
<managed-bean-scope>
none|request|session|application
</managed-bean-scope>
[<managed-property>
[<description [xml:lang="lang"]>description</description>]*
[<display-name [xml:lang="lang"]>displayName</display-name>]*
[<icon [xml:lang="lang"]>
[<small-icon>iconPath</small-icon>]
[<large-icon>iconPath</large-icon>]
</icon>]*
<property-name>propName</property-name>
[<property-class>className</property-class>]
<map-entries>
[<key-class>className</key-class>]
[<value-class>className</value-class>]
<map-entry>
<key>key</key>
<null-value/> | <value>value</value>
</map-entry>*
</map-entries> |
<null-value/>] |
<value>value</value> |
<list-entries>
[<value-class>className</value-class>]
<list-entry>
<null-value>/ | <value>value</value>
</list-entry>*
</list-entries>
</managed-property>* |
<map-entries>...</map-entries> |
<list-entries>...</list-entries>
]
</managed-bean>
The managed bean name, the fully qualified class name, and the scope
are declared by three mandatory elements:
<managed-bean-name>,
<managed-bean-class>, and
<managed-bean-scope>.
Values for the bean's properties can be declared
with <managed-property> elements, with a
nested <property-name> element containing
the name of the property, an optional
<property-class> element declaring the
property data type, and one element of type
<null-value>,
<value>,
<map-entries>, or
<list-entries> for the property value. The
<null-value> element sets the property to
null and the <value> element sets the
property to the element content; either an explicit value or a JSF EL
expression:
<managed-bean>
<managed-bean-name>myBean</managed-bean-name>
<managed-bean-class>com.mycompany.MyBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>myProperty</property-name>
<value>myValue</value>
</managed-property>
<managed-property>
<property-name>myDynamicProperty</property-name>
<value>#{anotherBean.aProperty}</value>
</managed-property>
</managed-bean>
A property of type java.util.Map is populated with
the <map-entries> element, containing
optional elements declaring the data types for the key and the value
and one or more <map-entry> elements with
nested <key>,
<null-value>, and
<value> elements. The key and value is
converted to the declared key and value data types before the map
entry is put in the Map.
Similarly, a property of type java.util.List of
Object[] is populated with the
<list-entries> element, containing optional
elements declaring the data type for the value and one or more
<list-entry> elements with nested
<null-value> and
<value> elements. The value is converted to
the declared value data types before the list entry is added to the
List or array.
A concrete implementation of the java.util.Map and
java.util.List interfaces can also be declared as
a managed bean. The <map-entries> or
<list-entries> elements can be used to
populate the entries of such a bean:
<managed-bean>
<managed-bean-name>myMap</managed-bean-name>
<managed-bean-class>java.util.HashMap</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<map-entries>
<value-class>java.lang.Integer</value-class>
<map-entry>
<key>Apple</key>
<value>1</value>
</map-entry>
<map-entry>
<key>Banana</key>
<value>2</value>
</map-entry>
</map-entries>
</managed-bean>
|