The Java EE 5 Tutorial

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). Here is part of the managed bean declaration for the ImageArea bean corresponding to the South America hotspot:


For more information on initializing managed beans with the managed bean creation facility, see the section Application Configuration Resource File.

The value attributes of the area tags refer to the beans in the application scope, as shown in this area tag from chooselocale.jsp:

<bookstore:area id="NAmerica"
         onmouseout="/template/world.jpg" />

To reference the ImageArea model object bean values from the component class, you implement a getValue method in the component class. This method calls super.getValue. The superclass of tut-install/javaeetutorial5/examples/web/bookstore6/src/java/com/sun/bookstore6/components/, UIOutput, has a getValue method that does the work of finding the ImageArea object associated with AreaComponent. The AreaRenderer class, which needs to render the alt, shape, and coords values from the ImageArea object, calls the getValue method of AreaComponent to retrieve the ImageArea object.

ImageArea iarea = (ImageArea) area.getValue();

ImageArea is only a simple bean, so you can access the shape, coordinates, and alternative text values by calling the appropriate accessor methods of ImageArea. Creating the Renderer Class explains how to do this in the AreaRenderer class.