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.

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

292<br />

<br />

<br />

<br />

<br />

<br />

For more information on the standard validators included with <strong>Java</strong>Server Faces technology,<br />

see “Using the Standard Validators” on page 359.<br />

Adding a Custom Message<br />

<strong>Java</strong>Server Faces technology provides standard error messages that display on the page when<br />

conversion or validation fails. In some cases, you might need to override the standard message.<br />

For example, if a user were to enter a letter into the text field on greeting.jsp, he or she would<br />

see the following error message:<br />

User Number: ’m’ must be a number between -2147483648 and 2147483647 Example: 9346<br />

This is wrong because the field really only accepts values from 0 through 10.<br />

To override this message, you add a converterMessage attribute on the inputText tag. This<br />

attribute references the custom error message:<br />

<br />

...<br />

<br />

<strong>The</strong> expression that converterMessage uses references the userNoConvert key of the ErrMsg<br />

resource bundle. <strong>The</strong> application architect needs to define the message in the resource bundle<br />

and configure the resource bundle. See “Configuring Error Messages” on page 295 for more<br />

information on this.<br />

See “Referencing Error Messages” on page 350 for more information on referencing error<br />

messages.<br />

Adding a Button<br />

<strong>The</strong> commandButton tag represents the button used to submit the data entered in the text field.<br />

<strong>The</strong> action attribute specifies an outcome that helps the navigation mechanism decide which<br />

page to open next. “Defining Page Navigation” on page 294 discusses this further.<br />

With the addition of the commandButton 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!