1

Setup: Primefaces 3.4.2, JSF2

I have a form with 4 input fields that posts data when onblur is triggered.

Description I put values into all of the 4 input fields and that works as it should. Then I start removing the values one by one. For all of the fields that has BigDecimalConverters I can not remove the values, as soon as I leave the field and start removing in the next one the value returns to the field.

I have used the network tab in the developer tools for IE and Chrome and I can see that the posts send the empty value and then it gets a respons saying that there should be a different number in the field.

Does anyone know what can cause this behaviour?

unzoomed
  • 580
  • 1
  • 6
  • 23
  • Can you provide your code piece? Related view page and managed bean code, it's imposible to provide a decent answer without that. – Aritz Nov 26 '13 at 11:21
  • I am afraid I can not do that. It is a part of a huge legacy system that does not like to do stuff like it is supposed to be so it generates almost all components on the serverside in java code. However I can see that the only thing that is different between the inputs is the IntegerConverter and BigDecimalConverter so I was hoping that someone had encountered a similar problem. – unzoomed Nov 26 '13 at 11:55
  • Is the number `198.23`? – kolossus Nov 26 '13 at 16:55

1 Answers1

3

The problem you're experiencing boils down to the following :

BigDecimal bg = new BigDecimal("");

The above line will throw a java.lang.NumberFormatException which will in turn result in a conversion error. This is the reason why the field values are being kept because the field failed validation/conversion.

The root cause is that blanks, by default are not submitted to the server as null. They're submitted as empty strings. This behaviour can be customized by setting the context parameter javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL to true in your web.xml. This will cause the empty fields to be sent as null and not trigger a conversion error.

Related:

Community
  • 1
  • 1
kolossus
  • 20,559
  • 3
  • 52
  • 104
  • 1
    This is exactly how I solved it in my (numerous) environments. If it is in-face submitting the empty string as a valid value this will solve it. If not, show some code. – Daniel B. Chapman Nov 26 '13 at 20:38