I'm setting up an input field for currency in my jsf web app and have a backing bean to write the value to. However the converter <f:convertNumber/>
doesn't seem to recognize correct input if entered by the user. The initial value can be submitted and numbers can be changed but typing in a value like
1,00 €
won't work. I would like to keep the formatter and also understand how to fix this problem.
I am using
JSF 2.3.5-SP2 (Mojarra)
withWildfly 14.0.1
andJava 10.0.1
I narrowed it down to the space between the number and the currency symbol but I don't know how to make <f:convertNumber/>
recognize a simple space as a correct input.
After doing a little inspection the original space was identified as a non-breaking space
This is my test code:
test.xhtml
<h:body>
<h:form>
<h:inputText value="#{testModel.number}">
<f:convertNumber type="currency" locale="de_DE" currencyCode="EUR"/>
</h:inputText>
<h:commandButton value="Submit" action="#{testModel.submit}"/>
<h:messages style = "color:red;margin:8px;" />
</h:form>
<h:outputText value="#{testModel.number}"/>
</h:body>
TestModel.java
@Named
@RequestScoped
public class TestModel {
private BigDecimal number;
public String submit(){
return "#";
}
public BigDecimal getNumber() {
if(number==null)number = new BigDecimal("0");
return number;
}
public void setNumber(BigDecimal number) {
this.number = number;
}
}
When changing the number to 1,00 € by only ereasing the 0 of 0,00 € and replacing it with a 1 I get the correct output.
When I replace the
(non-breaking) space between the number and the '€' symbol with a simple space the messsage shows the following warning:
j_idt3:j_idt4: '0,00 €' konnte nicht als Währungswert interpretiert werden.
meaning '0,00 €' couldn't be interpreted as a currency value.