background image

Initializing Array and List Properties

<< The map-entries Tag | The CustomerBean Declaration >>
<< The map-entries Tag | The CustomerBean Declaration >>

Initializing Array and List Properties

Initializing Array and List Properties
The list-entries element is used to initialize the values of an array or List property. Each
individual value of the array or List is initialized using a value or null-value element. Here is
an example:
<managed-bean>
...
<managed-property>
<property-name>books</property-name>
<list-entries>
<value-class>java.lang.String</value-class>
<value>Web Servers for Fun and Profit</value>
<value>#{myBooks.bookId[3]}</value>
<null-value/>
</list-entries>
</managed-property>
</managed-bean>
This example initializes an array or a List. The type of the corresponding property in the bean
determines which data structure is created. The list-entries element defines the list of values
in the array or List. The value element specifies a single value in the array or List and can
reference a property in another bean. The null-value element will cause the setBooks method
to be called with an argument of null. A null property cannot be specified for a property whose
data type is a Java primitive, such as int or boolean.
Initializing Managed Bean Properties
Sometimes you might want to create a bean that also references other managed beans so that
you can construct a graph or a tree of beans. For example, suppose that you want to create a
bean representing a customer's information, including the mailing address and street address,
each of which is also a bean. The following managed-bean declarations create a CustomerBean
instance that has two AddressBean properties: one representing the mailing address, and the
other representing the street address. This declaration results in a tree of beans with
CustomerBean
as its root and the two AddressBean objects as children.
<managed-bean>
<managed-bean-name>customer</managed-bean-name>
<managed-bean-class>
com.mycompany.mybeans.CustomerBean
</managed-bean-class>
<managed-bean-scope> request </managed-bean-scope>
<managed-property>
<property-name>mailingAddress</property-name>
<value>#{addressBean}</value>
</managed-property>
<managed-property>
Configuring Beans
Chapter 14 · Configuring JavaServer Faces Applications
445