Posts

Showing posts from February, 2012

Passing null to the model in JSF

The problem JSF allows you to bind an input component to a model bean via a so-called value binding. A notorious major headache is that a null is automatically coerced into a zero (0) when the bounded property is of type Integer or Long. This behavior only seems to rarely be the required one. A number of other types are coerced as well, e.g. in case of Boolean it's coerced to Boolean.FALSE . Finding a solution Although coercing is a literal interpretation of the spec, it seems that basically only Tomcat that implements this somewhat peculiar behavior. They have a setting to turn this off: -Dorg.apache.el.parser.COERCE_TO_ZERO=false See e.g. jsf: integer property binded to a inputtext in UI is set to zero on submit If you're in a position to use this option, don't read further and use it. If you can't use this option (you have e.g. a big system, lots of testing needed) and a null is needed at only a few places, another option is required. One possibi