10.12.2012 Views

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

To specify where state is saved for a particular web application, you need to set the<br />

javax.faces.STATE_SAVING_METHOD context parameter to either client or server in your<br />

application’s deployment descriptor. See “Saving and Restoring State” on page 424 for more<br />

information on specifying where state is saved in the deployment descriptor.<br />

Delegating Rendering to a Renderer<br />

Both MapComponent and AreaComponent delegate all of their rendering to a separate renderer.<br />

<strong>The</strong> section “Performing Encoding” on page 420 explains how MapRenderer performs the<br />

encoding for MapComponent. This section explains in detail the process of delegating rendering<br />

to a renderer using AreaRenderer, which performs the rendering for AreaComponent.<br />

To delegate rendering, you perform these tasks:<br />

■ Create the Renderer class.<br />

■ Register the renderer with a render kit (explained in “Registering a Custom Renderer with a<br />

Render Kit” on page 452).<br />

■ Identify the renderer type in the component’s tag handler.<br />

Creating the Renderer Class<br />

When delegating rendering to a renderer, you can delegate all encoding and decoding to the<br />

renderer, or you can choose to do part of it in the component class. <strong>The</strong> AreaComponent class<br />

delegates encoding to the AreaRenderer class.<br />

To perform the rendering for AreaComponent, AreaRenderer must implement an encodeEnd<br />

method. <strong>The</strong> encodeEnd method of AreaRenderer retrieves the shape, coordinates, and<br />

alternative text values stored in the ImageArea bean that is bound to AreaComponent. Suppose<br />

that the area tag currently being rendered has a value attribute value of "fraA". <strong>The</strong> following<br />

line from encodeEnd gets the value of the attribute "fraA" from the FacesContext instance.<br />

ImageArea ia = (ImageArea)area.getValue();<br />

<strong>The</strong> attribute value is the ImageArea bean instance, which contains the shape, coords, and alt<br />

values associated with the fraA AreaComponent instance. “Configuring Model Data” on<br />

page 414 describes how the application stores these values.<br />

After retrieving the ImageArea object, it renders the values for shape, coords, and alt by<br />

simply calling the associated accessor methods and passing the returned values to the<br />

ResponseWriter instance, as shown by these lines of code, which write out the shape and<br />

coordinates:<br />

writer.startElement("area", area);<br />

writer.writeAttribute("alt", iarea.getAlt(), "alt");<br />

Delegating Rendering to a Renderer<br />

Chapter 13 • Creating Custom UI Components 425

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!