Reputation: 2506
I have my struts.xml:
<s:textfield id="thresholdParameter_1"
name="gmathreshold.distinctBnumberRatio">
</s:textfield></td>
where gmathreshold is a bean with distinctBnumberRatio
as member variable. In my bean it's a BigDecimal
. So how can I get it set in my Bean. I mean how to convert from String
to BigDecimal
in struts2??
Upvotes: 0
Views: 1500
Reputation: 12983
how to convert from String to
BigDecimal
The BigDecimal(java.lang.String) constructor takes String
argument.
Translates the string representation of a
BigDecimal
into aBigDecimal
. The string representation consists of an optional sign, '+' ( '\u002B') or '-' ('\u002D'), followed by a sequence of zero or more decimal digits ("the integer"), optionally followed by a fraction, optionally followed by an exponent.
For example,
String distinctBnumberRatioStr = "124.20";
BigDecimal distinctBnumberRatio = new BigDecimal(str);
Answer to you comment
String in JSP to BigDecimal in ActionClass
From docs TypeConversion-BuiltinTypeConversionSupport
Type Conversion is implemented by XWork.
XWork will automatically handle the most common type conversion for you. This includes support for converting to and from Strings for each of the following:
Note that with arrays the type conversion will defer to the type of the array elements and try to convert each item individually. As with any other type conversion, if the conversion can't be performed the standard type conversion error reporting is used to indicate a problem occured while processing the type conversion.
Upvotes: 1