background image

Configuring Model Data

<< The actionListener Attribute | Summary of the Application Classes >>
<< The actionListener Attribute | Summary of the Application Classes >>

Configuring Model Data

onmouseover
and onmouseout attribute values indicate the image to be loaded when these
events occur. How the JavaScript is generated is explained more in
"Performing Encoding" on
page 422
.
The coordinate, shape, and alternate text data are obtained through the value attribute, whose
value refers to an attribute in application scope. The value of this attribute is a bean, which
stores the coords, shape, and alt data. How these beans are stored in the application scope is
explained more in the next section.
Configuring Model Data
In a JavaServer Faces application, data such as the coordinates of a hotspot of an image map is
retrieved from the value attribute through a bean. However, the shape and coordinates of a
hotspot should be defined together because the coordinates are interpreted differently
depending on what shape the hotspot is. Because a component's value can be bound only to one
property, the value attribute cannot refer to both the shape and the coordinates.
To solve this problem, the application encapsulates all of this information in a set of ImageArea
objects. These objects are initialized into application scope by the managed bean creation
facility (see
"Backing Beans" on page 309
). Here is part of the managed bean declaration for the
ImageArea
bean corresponding to the South America hotspot:
<managed-bean>
...
<managed-bean-name>SA</managed-bean-name>
<managed-bean-class>
components.model.ImageArea
</managed-bean-class>
<managed-bean-scope>application</managed-bean-scope>
<managed-property>
<property-name>shape</property-name>
<value>poly</value>
</managed-property>
<managed-property>
<property-name>alt</property-name>
<value>SAmerica</value>
</managed-property>
<managed-property>
<property-name>coords</property-name>
<value>89,217,95,100...</value>
</managed-property>
</managed-bean>
For more information on initializing managed beans with the managed bean creation facility,
see the section
"Application Configuration Resource File" on page 437
.
Understanding the Image Map Example
The Java EE 5 Tutorial · September 2007
416