Rendering the View
When JSP is used as the presentation layer technology, the JSP container processes the JSP page that defines the view as any JSP page so only the JSF custom action tag handlers can influence what happens. The part of the page that consists of template text and regular standard and custom actions is totally under the control of the JSP container, and JSF must play nice to render the markup for the components where it belongs relative to the other type of content.
Besides creating JSF components, the tag handlers also ask each
component to render itself. Two rendering methods the tag handlers
call for each component are named encodeBegin()
and encodeEnd()
. The encodeBegin(
)
method
typically writes an opening tag (e.g.,
<form>
for the form component), while
encodeEnd()
writes a closing tag (e.g.,
</form>
) or a single tag for a component
that doesn’t require separate opening and closing
tags (e.g., an input component that generates a single HTML
<input>
tag). As you know by now, the
component classes typically don’t generate output
directly. Instead, they delegate this task to a renderer. This is
true for all components defined by the JSF specification, and it is
the recommended behavior for custom components. The component
rendering methods just obtain an instance of their renderer and call
methods with the same name on the renderer:
package javax.faces.component; import javax.faces.context.FacesContext; import javax.faces.render.Renderer; import javax.faces.webapp.UIComponentTag; ...
Get JavaServer Faces now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.