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

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

问题描述

我们在JSF页面中使用 h:inputText ,该页面绑定到 Integer 属性(因此可以接受 null )。当 h:inputText 中没有写入值时,表单提交 0 而不是。我们正在使用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?

推荐答案

这个特征是EL中的一个错误修正的结果,每个Tomcat 6.0.16。根据 EL规范的第1.18.3章,数字类型的值 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引入了一个新的配置设置,这将禁用这个错误修复。

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

我顺便请求更改此规范应该只将空/空原始类型强制为零,空/空非原始 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.

  • The empty String madness
  • How to make number input area initially empty instead of 0 or 0.00?
  • How to set -Dorg.apache.el.parser.COERCE_TO_ZERO=false programmatically
  • Work around for faulty INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL in Mojarra JSF 2.1

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

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