background image

Initializing Maps and Lists

<< The CustomerBean Declaration | Registering Custom Error Messages >>
<< The CustomerBean Declaration | Registering Custom Error Messages >>

Initializing Maps and Lists

TABLE 14­2
Allowable Connections between Scoped Objects
(Continued)
An Object of This Scope
May Point to an Object of This Scope
request
none
, application, session, request
Be sure not allow cyclical references between objects. For example, neither of the AddressBean
objects in the preceding example should point back to the CustomerBean object because
CustomerBean
already points to the AddressBean objects.
Initializing Maps and Lists
In addition to configuring Map and List properties, you can also configure a Map and a List
directly so that you can reference them from a tag rather than referencing a property that wraps
a Map or a List.
The Duke's Bookstore application configures a List to initialize the list of free newsletters, from
which users can choose a set of newsletters to subscribe to on the bookcashier.jsp page:
<managed-bean>
...
<managed-bean-name>newsletters</managed-bean-name>
<managed-bean-class>
java.util.ArrayList
</managed-bean-class>
<managed-bean-scope>application</managed-bean-scope>
<list-entries>
<value-class>javax.faces.model.SelectItem</value-class>
<value>#{newsletter0}</value>
<value>#{newsletter1}</value>
<value>#{newsletter2}</value>
<value>#{newsletter3}</value>
</list-entries>
</managed-bean>
<managed-bean>
<managed-bean-name>newsletter0</managed-bean-name>
<managed-bean-class>
javax.faces.model.SelectItem
</managed-bean-class>
<managed-bean-scope>none</managed-bean-scope>
<managed-property>
<property-name>label</property-name>
<value>Duke
's Quarterly</value>
</managed-property>
<managed-property>
<property-name>value</property-name>
<value>200</value>
Configuring Beans
Chapter 14 · Configuring JavaServer Faces Applications
447