JSF页面绑定Integer类型值form提交时变成0的解决方案
Posted on: 2020-04-21, Last modified: 2020-04-21, View: 239

The primitive int always defaults to 0. You want to use Integer instead. E.g.:

public class Entity {

    private Integer value;

    // ...
}

As to keeping it null while submitting empty data, add the following context param to your web.xml:

<context-param>
    <param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
    <param-value>true</param-value>
</context-param>

In addition, if you're using Tomcat or a clone which utilizes Apache EL parser, add the following server startup VM argument as well to prevent it from treating Number values like primitives:

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

In Eclipse, you could set it in server configuration (doubleclick the server entry in Servers view) in the Arguments tab of the Open launch configuration dialogue. In production, you could add it to the JAVA_OPTS environment variable.

From: https://stackoverflow.com/questions/7206401/jsf-2-hiding-default-values-on-extends-number/7206474#7206474
Go
Friend Links:
Bill Site
https://item.taobao.com/item.htm?spm=a21an.7676007.1998473182.296.lAvrE2&id=45399580446