Friday, July 08, 2011

JSF Bug - Number Based Input Field Magically Changes From 'null' To Zero

The problem:
Submitting a form and the number based fields (BigDecimal/Number/Integer etc) that had an empty string (null) on the form get populated with zero ("0") values.

The problem domain:
Tomcat/JBoss servers. I am running JBoss 5.1.0.GA.

The solution:
It appears the team at Tomcat didn't want us to be able to have nullable number fields in a JSF form! The solution is to set this java system variable: "org.apache.el.parser.COERCE_TO_ZERO=false", e.g.:

run.bat -Dorg.apache.el.parser.COERCE_TO_ZERO=false

This was a bit of a nightmare to track down, I tried writing and stepping through custom converters and thought I was going insane. Hopefully this helps someone out there.

P.S. I know I said this is a bug, but technically (crazily?) the spec does say to convert null's to 0's. See: http://tomcat.apache.org/tomcat-6.0-doc/config/systemprops.html.

4 comments:

website design Hyderabad said...

Thank you for sharing information about web designing& development.

Simon said...

My pleasure, good to hear people find the info useful.

Custom Soft said...

Thank you for sharing information about Java web development bugs.
I think, I can give its solution after some research

Paul Frischknecht said...

I'd call it a bug in the spec.