background image

Valid Bean Property Assignments

<< Setting JavaBeans Component Properties | Retrieving JavaBeans Component Properties >>
<< Setting JavaBeans Component Properties | Retrieving JavaBeans Component Properties >>

Valid Bean Property Assignments

TABLE 5­6
Valid Bean Property Assignments from String Values
(Continued)
Value Source
Element Syntax
Request parameter name that
matches bean property
<jsp:setProperty name=
"beanName"
property=
"propName"/>
<jsp:setProperty name=
"beanName"
property=
"*"/>
Expression
<jsp:setProperty name=
"beanName"
property=
"propName" value="expression"/>
<jsp:setProperty name=
"beanName"
property=
"propName" >
<jsp:attribute name=
"value">
expression
</jsp:attribute>
</jsp:setProperty>
A property set from a constant string or request parameter must have one of the types listed in
Table 5­7
. Because constants and request parameters are strings, the web container
automatically converts the value to the property's type; the conversion applied is shown in the
table.
String
values can be used to assign values to a property that has a PropertyEditor class. When
that is the case, the setAsText(String) method is used. A conversion failure arises if the
method throws an IllegalArgumentException.
The value assigned to an indexed property must be an array, and the rules just described apply
to the elements.
You use an expression to set the value of a property whose type is a compound Java
programming language type. The type returned from an expression must match or be castable
to the type of the property.
TABLE 5­7
Valid Property Value Assignments from String Values
Property Type
Conversion on String Value
Bean Property
Uses setAsText(string-literal)
boolean
or Boolean
As indicated in java.lang.Boolean.valueOf(String)
byte
or Byte
As indicated in java.lang.Byte.valueOf(String)
char
or Character
As indicated in java.lang.String.charAt(0)
double
or Double
As indicated in java.lang.Double.valueOf(String)
int
or Integer
As indicated in java.lang.Integer.valueOf(String)
JavaBeans Components
The Java EE 5 Tutorial · September 2007
170