How to set -Dorg.apache.el.parser.COERCE_TO_ZERO=false programmatically

后端 未结 1 1045
-上瘾入骨i
-上瘾入骨i 2020-11-30 02:01

This question is similar to:

jsf: integer property binded to a inputtext in UI is set to zero on submit

but I am not completely satisfied with the solution.

相关标签:
1条回答
  • 2020-11-30 02:29

    You can set the system properties programmatically using System#setProperty().

    System.setProperty("org.apache.el.parser.COERCE_TO_ZERO", "false");
    

    However, you need to ensure that this is been set before JSF/EL ever get initialized. Best place would be a ServletContextListener.

    public class Config implements ServletContextListener {
    
        @Override
        public void contextInitialized(ServletContextEvent event) {
            System.setProperty("org.apache.el.parser.COERCE_TO_ZERO", "false");
        }
    
        @Override
        public void contextDestroyed(ServletContextEvent event) {
            // NOOP
        }
    
    }
    

    Register it as <listener> in web.xml, or when you're already on Servlet 3.0 (Tomcat 7 and so), with @WebListener annotation.

    0 讨论(0)
提交回复
热议问题