O'Reilly logo

JavaServer Faces by Hans Bergsten

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required