Download
FAQ History |
![]() ![]() ![]() |
API
Search Feedback |
Creating the Component Tag Handler
If you've created your own JSP custom tags before, creating a component tag and tag handler should be easy for you.
In JavaServer Faces applications, the tag handler class associated with a component drives the Render Response phase of the JavaServer Faces lifecycle. For more information on the JavaServer Faces lifecycle, see The Lifecycle of a JavaServer Faces Page (page 791). The first thing that the tag handler does is retrieve the type of the component associated with the tag. Next, it sets the component's attributes to the values given in the page. Finally, it returns the type of the renderer (if there is one) to the JavaServer Faces implementation so that the component's encoding can be performed when the tag is processed.
The image map custom component includes two tag handlers:
AreaTag
andMapTag
. To see how the operations on a JavaServer Faces tag handler are implemented, let's take a look atMapTag
:public class MapTag extends FacesTag { public String currentArea = null; public MapTag(){ super(); } public String getCurrentArea() { return currentArea; } public void setCurrentArea(String area) { currentArea = area; } public void overrideProperties(UIComponent component) { super.overrideProperties(component); UIMap map = (UIMap) component; if(map.getAttribute("currentArea") == null) map.setAttribute("currentArea", getCurrentArea()); } public String getRendererType() { return null; } public UIComponent createComponent() { return (new UIMap()); } } // end of classThe first thing to notice is that
MapTag
extendsFacesTag
, which supportsjsp.tagext.Tag
functionality as well as JavaServer Faces-specific functionality.FacesTag
is the base class for all JavaServer Faces tags that correspond to a component. Tags that need to process their tag bodies should subclassFacesBodyTag
instead.As explained above, the first thing
MapTag
does is to retrieve the type of the component. This is done with thegetComponentType
operation,:Next, the tag handler sets the component's attribute values to those supplied as tag attributes in the page. The
MapTag
handler gets the attribute values from the page via JavaBeans properties that correspond to the attributes.UIMap
only has one attribute,currentArea
. Here is the property used to access the value ofcurrentArea
:public String currentArea = null; ... public String getCurrentArea() {return currentArea;} public void setCurrentArea(String area) { currentArea = area; }To pass the value of
currentArea
to theUIMap
component, the tag handler implements theoverrideProperties
method, which calls theUIMap.setAttribute
method with the name and value ofcurrentArea
attribute:public void overrideProperties(UIComponent component) { super.overrideProperties(component); UIMap map = (UIMap) component; if(map.getAttribute("currentArea") == null) map.setAttribute("currentArea", getCurrentArea()); }Finally, the tag handler provides a renderer type--if there is a renderer associated with the component--to the JavaServer Faces implementation. It does this with the
getRendererType
method:Since
UIMap
does not have a renderer associated with it, this method returns null. In this case, the JavaServer Faces implementation will invoke the encoding methods ofUIMap
to perform the rendering.Delegating Rendering to a Renderer provides an example of returning a renderer from this method.
Download
FAQ History |
![]() ![]() ![]() |
API
Search Feedback |
All of the material in The Java(TM) Web Services Tutorial is copyright-protected and may not be published in other works without express written permission from Sun Microsystems.