Friday, March 1, 2019

JBoss 7 - JSF null value input become 0

this problem occures when binding an input in jsf to a numeric attribute in the bean.
Usually when we are running the app on apache tomcat we addthis jvm paramter in the tomcat VM
-Dorg.apache.el.parser.COERCE_TO_ZERO=false

For those who are running on JBoss Server 7.x
adding a context parameter


<context-param>
    <param-name>javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL</param-name>
    <param-value>true</param-value>
</context-param> 
in standalone.xml file did not work for me.
One working solution is to create is to add a listener to your web app that adds this parameter dynamically
Here is the code

'Here i'm using WebListener annotation'

  
package com.cnss.ds.web.utils;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;


@WebListener
public class AppWebLsistener  implements ServletContextListener {
 @Override
    public void contextInitialized(ServletContextEvent event) {

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

 @Override
 public void contextDestroyed(ServletContextEvent arg0) {
  // TODO Auto-generated method stub
  
 }

}

No comments:

Post a Comment