Convert empty number as null

2019-05-28 18:53发布

问题:

is there a possibility to tell my JSF-implementation to convert empty numbers as null. So far I always get 0 (of the corresponging complex-type).
For empty strings there is javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL, but I couldn't find anything for numbers. By the way: No, I can't use the vm-argument: -Dorg.apache.el.parser.COERCE_TO_ZERO=false

Is a custom-numberconverter my only possibility?

回答1:

No, I can't use the vm-argument: -Dorg.apache.el.parser.COERCE_TO_ZERO=false

The problem is in EL implementation used by the server, not in JSF. You really need to use the VM argument. If you can't use it then your problem can't be solved by other way than downgrading Tomcat to 6.0.15 or older, or replacing the server by for example Glassfish. It was Tomcat 6.0.16 when this "improved" EL coercion behaviour was introduced.

If you elaborate the exact reason why you can't use it (it makes at least no sense to me), then we may be able to propose ways how to really use it. For example, if it's ignorance how to set a VM argument, then say so. Or if you're not allowed to add a VM argument to startup script because it's a 3rd party maintained server, then say so. Both problems can be solved so that you can use the VM argument rightly.



回答2:

Used to be -Dorg.glassfish.el.COERCE_TO_ZERO=true: https://java.net/projects/uel/lists/issues/archive/2012-04/message/1 Now (Glassfish v4) in vain! https://java.net/projects/uel/lists/commits/archive/2012-04/message/3