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 property set from a constant string or request parameter must have one of the types listed in<br />

Table 5–7. Because constants and request parameters are strings, the web container<br />

automatically converts the value to the property’s type; the conversion applied is shown in the<br />

table.<br />

String values can be used to assign values to a property that has a PropertyEditor class. When<br />

that is the case, the setAsText(String) method is used. A conversion failure arises if the<br />

method throws an IllegalArgumentException.<br />

<strong>The</strong> value assigned to an indexed property must be an array, and the rules just described apply<br />

to the elements.<br />

You use an expression to set the value of a property whose type is a compound <strong>Java</strong><br />

programming language type. <strong>The</strong> type returned from an expression must match or be castable<br />

to the type of the property.<br />

TABLE 5–7 Valid Property Value Assignments from String Values<br />

PropertyType Conversion on StringValue<br />

Bean Property Uses setAsText(string-literal)<br />

boolean or Boolean As indicated in java.lang.Boolean.valueOf(String)<br />

byte or Byte As indicated in java.lang.Byte.valueOf(String)<br />

char or Character As indicated in java.lang.String.charAt(0)<br />

double or Double As indicated in java.lang.Double.valueOf(String)<br />

int or Integer As indicated in java.lang.Integer.valueOf(String)<br />

float or Float As indicated in java.lang.Float.valueOf(String)<br />

long or Long As indicated in java.lang.Long.valueOf(String)<br />

short or Short As indicated in java.lang.Short.valueOf(String)<br />

Object new String(string-literal)<br />

<strong>The</strong> Duke’s Bookstore application demonstrates how to use the setProperty element to set the<br />

current book from a request parameter in the database bean in<br />

tut-install/javaeetutorial5/examples/web/bookstore2/web/books/bookdetails.jsp:<br />

<br />

<br />

<strong>Java</strong>Beans Components<br />

<strong>The</strong> following fragment from the page<br />

tut-install/javaeetutorial5/examples/web/bookstore2/web/books/bookshowcart.jsp<br />

Chapter 5 • <strong>Java</strong>Server PagesTechnology 169

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

Saved successfully!

Ooh no, something went wrong!