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.

Using the Standard Converters<br />

354<br />

<br />

<br />

<br />

Instead of using the converterId attribute, the converter tag can use the binding attribute.<br />

<strong>The</strong> binding attribute must resolve to a bean property that accepts and returns an appropriate<br />

Converter instance. See “Binding Converters, Listeners, and Validators to Backing Bean<br />

Properties” on page 367 for more information.<br />

Using DateTimeConverter<br />

You can convert a component’s data to a java.util.Date by nesting the convertDateTime tag<br />

inside the component tag. <strong>The</strong> convertDateTime tag has several attributes that allow you to<br />

specify the format and type of the data. Table 11–5 lists the attributes.<br />

Here is a simple example of a convertDateTime tag from the bookreceipt.jsp page:<br />

<br />

<br />

<br />

When binding the DateTime converter to a component, ensure that the backing bean property<br />

to which the component is bound is of type java.util.Date. In the case of the preceding<br />

example, cashier.shipDate must be of type java.util.Date.<br />

Here is an example of a date and time that the preceding tag can display:<br />

Saturday, Feb 22, 2003<br />

You can also display the same date and time using this tag:<br />

<br />

<br />

<br />

If you want to display the example date in Spanish, you can use the locale attribute:<br />

<br />

<br />

<br />

This tag would display<br />

sabado 23 de septiembre de 2006<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!