I’m trying save a values’ input field to a BigDecimal. Which already works.
But it produces strange results if I enter decimal deliminator that is not of the locale type.
eg:
class Payment {
BigDecimal amount;
}
<p:inputText id="amount" value="#{payment.amount}">
<f:convertNumber locale="en"/>
</p:inputText>
<h:outputText value="#{payment.amount}" />
If I input 10,10
I get: 1,010.00
So the value is taken as 1010
How could I work around this? What am I doing wrong here?
ty
The commas are not significant when parsing an English-locale number. Java’s raw
Numbertypes will not retain any formatting information – that’s just presentation data.The logic for the
inputTextwith a NumberConverter goes like this:The
outputTextdoesn’t have a converter, so will merely calltoString()on its value binding (theBigDecimal.)I would expect the results to be
1,010and1010.0respectively.The behavior of
NumberConverteris documented in the javadoc. The rules for EL type coercion are documented in JSR 245:If you want to use the user’s browser locale to interpret number formats, remove the locale attribute. If you want a converter to treat both periods and commas as decimal separators, provide your own Converter implementation.