Java Reference
In-Depth Information
Input
Result
"72%"
0.72
"72 %"
0.72
"-84"
-0.84
"0.5"
0.005
"(45%)"
-0.45
"(45)"
-0.45
The One-to-Many Type Converter
The OneToManyTypeConverter is a nifty type converter that accepts a list
of values in one String input and converts them into a Collection<T> , con-
verting each individual value to T . For example, if you declare the prop-
erty to be a Collection<Long> , each value will be converted to a Long and
added to the collection. If you just use Collection without declaring the
type <T> of the individual items, Stripes uses String by default.
Each value in the input string has to be separated by either of the
following:
• One or more spaces
• A comma followed by one or more spaces
Note that a comma alone is not treated as a separator by OneToMany-
TypeConverter , because a comma could be used within a single value,
such as a thousands separator in a numerical value.
Instead of type converting the input string, OneToManyTypeConverter
extracts the values and passes each individual value to the type con-
verter for the type inside the collection. For example, using OneToMany-
TypeConverter on a List<Long> property will use the LongTypeConverter to
convert each value to a Long and will put all the values in List .
Although OneToManyTypeConverter does not produce any validation
errors, it does transmit any errors that occur when converting the indi-
vidual values.
Here are some examples of inputs and results:
Input
Property Type
Result
"a b c d"
["a", "b", "c", "d"]
List<String>
"a, b, c"
["a", "b", "c"]
List<String>
"a,b,c d, e"
["a,b,c", "d", "e"]
List<String>
"1, 2.5, -3 4"
[1.0, 2.5, -3.0, 4.0]
List<Double>
 
 
Search WWH ::




Custom Search