Convert empty number as null

馋奶兔 提交于 2019-12-22 18:16:13

问题


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



来源:https://stackoverflow.com/questions/10282777/convert-empty-number-as-null

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!