绑定到 Integer 属性的 h:inputText 正在提交值 0 而不是 null [英] h:inputText which is bound to Integer property is submitting value 0 instead of null

查看:32
本文介绍了绑定到 Integer 属性的 h:inputText 正在提交值 0 而不是 null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们在 JSF 页面中使用 h:inputText,该页面绑定到 Integer 属性(因此可以接受 null).当 h:inputText 中没有写入值时,表单提交的是 0 而不是 null.我们使用的是 Trinidad 1.2.2 和 Tomcat 6.0.20(我们也尝试使用 Tomcat 6.0.14,因为我们了解到某些 Tomcat 版本可能会发生这种情况).

We are using a h:inputText in a JSF page which is bound to an Integer property (and thus can accept null). When there is no value written in the h:inputText, the form is submitting a 0 instead of null. We are using Trinidad 1.2.2 and Tomcat 6.0.20 (we also tried with Tomcat 6.0.14 as we read that this could happen with certains Tomcat versions).

这是怎么引起的,我该如何解决?

How is this caused and how can I solve it?

推荐答案

这个功能"是根据 Tomcat 6.0.16 引入的 EL 中的错误修复的结果.根据 EL 规范,null 的数字类型值应该被强制为 0.在 Tomcat 6.0.16 之前,这是错误的".被强制为空字符串.

This "feature" was result of a bugfix in EL which was introduced as per Tomcat 6.0.16. As per chapter 1.18.3 of the EL specification, a value of number type which is null should be coerced to 0. Before Tomcat 6.0.16 this was "incorrectly" been coerced to an empty string.

毕竟,空字符串实际上比零更直观.Apache 的 Tomcat 人员收到了很多关于此错误修复的投诉,因此他们根据 Tomcat 6.0.17 引入了一种新的配置设置,该配置设置类似于 VM 参数,这将禁用此错误修复.

After all, an empty string was actually much more intuitive than a zero. The Tomcat guys at Apache got a lot complaints about this bugfix, so they introduced a new configuration setting in flavor of a VM argument as per Tomcat 6.0.17 which would disable this bugfix.

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

顺便说一句,我请求更改此规范,它应该只将空/null primitive 类型强制为零和空/null non-primitive java.lang.Number 类型为空字符串:JSP EL issue 184.他们没有做太多,但这个问题至少得到了很多选票.谁知道...这种行为至少确实很烦人,因为它不直观.

I've by the way requested a change to this spec that it should only coerce empty/null primitive types to zero and empty/null non-primitive java.lang.Number types to empty string: JSP EL issue 184. They did not much with it, but the issue at least got a lot of votes. Who knows... This behaviour is at least indeed pretty annoying because it's non-intuitive.

这篇关于绑定到 Integer 属性的 h:inputText 正在提交值 0 而不是 null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆