Java Reference
In-Depth Information
MapComponent map = (MapComponent) component;
ResponseWriter writer = context.getResponseWriter();
writer.startElement("input", map);
writer.writeAttribute("type", "hidden", null);
writer.writeAttribute("name", getName(context,map), "clien-
tId");(
writer.endElement("input");
writer.endElement("map");
}
Notice that encodeBegin renders only the beginning map tag. The encodeEnd meth-
od renders the input tag and the ending map tag.
The encoding methods accept a UIComponent argument and a
javax.faces.context.FacesContext argument. The FacesContext in-
stance contains all the information associated with the current request. The UICompon-
ent argument is the component that needs to be rendered.
The rest of the method renders the markup to the
javax.faces.context.ResponseWriter instance, which writes out the markup
to the current response. This basically involves passing the HTML tag names and attribute
names to the ResponseWriter instance as strings, retrieving the values of the com-
ponent attributes, and passing these values to the ResponseWriter instance.
The startElement method takes a String (the name of the tag) and the component
to which the tag corresponds (in this case, map ). (Passing this information to the Re-
sponseWriter instance helps design-time tools know which portions of the generated
markup are related to which components.)
After calling startElement , you can call writeAttribute to render the tag's at-
tributes. The writeAttribute method takes the name of the attribute, its value, and
the name of a property or attribute of the containing component corresponding to the at-
tribute. The last parameter can be null, and it won't be rendered.
The name attribute value of the map tag is retrieved using the getId method of UICom-
ponent , which returns the component's unique identifier. The name attribute value of
the input tag is retrieved using the getName(FacesContext, UIComponent)
method of MapRenderer .
If you want your component to perform its own rendering but delegate to a renderer if
there is one, include the following lines in the encoding method to check whether there is
a renderer associated with this component:
Search WWH ::




Custom Search