Using SpringMVC + Thymeleaf, how does one bind an integer based model attribute, to an input field in a form using th:value or th:field, without having a value of '0' show in the field itself.
The issue is not with Thymeleaf, it is on the EL implementation of Tomcat. It doesn't respect the difference between the nullable Integer
and primitive int
. It is always coercing null values to 0. You can turn off this behavior using this VM argument :
-Dorg.apache.el.parser.COERCE_TO_ZERO=false
or programatically by
System.setProperty("org.apache.el.parser.COERCE_TO_ZERO", "false");
If you choose the programatic way, make sure that you invoke it during initialization of ServletContext
(ServletContextListener#contextInitialized
)