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.

Delegating Rendering to a Renderer<br />

426<br />

writer.writeAttribute("coords", iarea.getCoords(), "coords");<br />

writer.writeAttribute("shape", iarea.getShape(), "shape");<br />

<strong>The</strong> encodeEnd method also renders the <strong>Java</strong>Script for the onmouseout, onmouseover, and<br />

onclick attributes. <strong>The</strong> page author need only provide the path to the images that are to be<br />

loaded during an onmouseover or onmouseout action:<br />

<br />

<strong>The</strong> AreaRenderer class takes care of generating the <strong>Java</strong>Script for these actions, as shown in the<br />

following code from encodeEnd. <strong>The</strong> <strong>Java</strong>Script that AreaRenderer generates for the onclick<br />

action sets the value of the hidden field to the value of the current area’s component ID and<br />

submits the page.<br />

sb = new StringBuffer("document.forms[0][’").<br />

append(targetImageId).append("’].src=’");<br />

sb.append(getURI(context,<br />

(String) area.getAttributes().get("onmouseout")));<br />

sb.append("’");<br />

writer.writeAttribute("onmouseout", sb.toString(),<br />

"onmouseout");<br />

sb = new StringBuffer("document.forms[0][’").<br />

append(targetImageId).append("’].src=’");<br />

sb.append(getURI(context,<br />

(String) area.getAttributes().get("onmouseover")));<br />

sb.append("’");<br />

writer.writeAttribute("onmouseover", sb.toString(),<br />

"onmouseover");<br />

sb = new StringBuffer("document.forms[0][’");<br />

sb.append(getName(context, area));<br />

sb.append("’].value=’");<br />

sb.append(iarea.getAlt());<br />

sb.append("’; document.forms[0].submit()");<br />

writer.writeAttribute("onclick", sb.toString(), "value");<br />

writer.endElement("area");<br />

By submitting the page, this code causes the <strong>Java</strong>Server Faces life cycle to return back to the<br />

restore view phase. This phase saves any state information, including the value of the hidden<br />

field, so that a new request component tree is constructed. This value is retrieved by the decode<br />

method of the MapComponent class. This decode method is called by the <strong>Java</strong>Server Faces<br />

implementation during the apply request values phase, which follows the restore view phase.<br />

In addition to the encodeEnd method, AreaRenderer contains an empty constructor. This is<br />

used to create an instance of AreaRenderer so that it can be added to the render kit.<br />

<strong>The</strong> <strong>Java</strong> <strong>EE</strong> 5<strong>Tutorial</strong> • June 2010

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

Saved successfully!

Ooh no, something went wrong!