Java Reference
In-Depth Information
bookId);
}
When the JavaServer Faces implementation calls this method, it passes in an Ac-
tionEvent object that represents the event generated by clicking on the image map.
Next, it casts it to an AreaSelectedEvent object (see tut-install /examples/
case-studies/dukes-bookstore/src/java/dukesbookstore/
listeners/AreaSelectedEvent.java ). Then this method gets the MapCom-
ponent associated with the event. It then gets the value of the MapComponent object's
current attribute, which indicates the currently selected area. The method then uses the
value of the current attribute to get the topic's ID value from a HashMap object, which
is constructed elsewhere in the MapBookChangeListener class. Finally the method
places the ID obtained from the HashMap object into the session map for the applica-
tion.
In addition to the method that processes the event, you need the event class itself. This
class is very simple to write: You have it extend ActionEvent and provide a construct-
or that takes the component on which the event is queued and a method that returns the
component.
Here is the AreaSelectedEvent class used with the image map:
Click here to view code image
public class AreaSelectedEvent extends ActionEvent {
public AreaSelectedEvent(MapComponent map) {
super(map);
}
public MapComponent getMapComponent() {
return ((MapComponent) getComponent());
}
}
As explained in the section “ Creating Custom Component Classes on page 106 , in order
for MapComponent to fire events in the first place, it must implement ActionSource .
Because MapComponent extends UICommand , it also implements ActionSource .
Defining the Custom Component Tag in a Tag Library Descriptor
To use a custom tag, you declare it in a Tag Library Descriptor (TLD). The TLD file
defines how the custom tag is used in a JavaServer Faces page. The web container uses the
TLD to validate the tag. The set of tags that are part of the HTML render kit are defined
Search WWH ::




Custom Search