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.

Programming SimpleTag Handlers<br />

264<br />

<br />

<br />

<br />

<br />

${departmentName}<br />

<br />

<br />

<br />

<br />

<br />

Tag Handler<br />

<strong>The</strong> collection is set in the tag handler by means of the group attribute. <strong>The</strong> tag handler retrieves<br />

an element from the group and passes the element back to the page in the EL variable whose<br />

name is determined by the var attribute. <strong>The</strong> variable is accessed in the calling page using the<br />

JSP expression language. After the variable is set, the tag body is evaluated with the invoke<br />

method.<br />

public void doTag() throws JspException, IOException {<br />

if (iterator == null)<br />

return;<br />

while (iterator.hasNext()) {<br />

getJspContext().setAttribute(var, iterator.next());<br />

getJspBody().invoke(null);<br />

}<br />

}<br />

public void setVar(String var) {<br />

this.var = var;<br />

}<br />

public void setGroup(Collection group) {<br />

this.group = group;<br />

if(group.size() > 0)<br />

iterator = group.iterator();<br />

}<br />

ATemplateTag Library<br />

A template provides a way to separate the common elements that are part of each screen from<br />

the elements that change with each screen of an application. Putting all the common elements<br />

together into one file makes it easier to maintain and enforce a consistent look and feel in all the<br />

screens. It also makes development of individual screens easier because the designer can focus<br />

on portions of a screen that are specific to that screen while the template takes care of the<br />

common portions.<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!