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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

A Simple <strong>Java</strong>Server Faces Application<br />

290<br />

Can you guess it?<br />

<br />

<br />

Adding an Image<br />

To display images on a page, you use the graphicImage tag. <strong>The</strong> url attribute of the tag specifies<br />

the path to the image file. Let’s add Duke to the page using a graphicImage tag:<br />

<br />

<br />

<br />

<br />

Hi. My name is Duke. I’m thinking of a number from<br />

to<br />

.<br />

Can you guess it?<br />

<br />

<br />

<br />

Adding aText Field<br />

<strong>The</strong> inputText tag represents a text field component. In the guessNumber example, this text<br />

field takes an integer input value. <strong>The</strong> instance of this tag included in greeting.jsp has three<br />

attributes: id, label, and value.<br />

<br />

...<br />

<br />

<strong>The</strong> id attribute corresponds to the ID of the component object represented by this tag. In this<br />

case, an id attribute is required because the message tag (which is used to display validation<br />

error messages) needs it to refer to the userNo component.<br />

<strong>The</strong> label attribute specifies the name to be used by error messages to refer to the component.<br />

In this example, label is set to User Number. As an example, if a user were to enter 23, the error<br />

message that would be displayed is:<br />

User Number: Validation Error: Value is greater than allowable maximum of 10.<br />

<strong>The</strong> value attribute binds the userNo component value to the bean property<br />

UserNumberBean.userNumber, which holds the data entered into the text field.<br />

After adding the inputText tag, the greeting page looks like the following:<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!