jsf:在UI中绑定到inputtext的integer属性在提交时设置为零 [英] jsf: integer property binded to a inputtext in UI is set to zero on submit

查看:148
本文介绍了jsf:在UI中绑定到inputtext的integer属性在提交时设置为零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的bean中有整数属性,绑定到jsp页面中的inputtext UI元素.

最初呈现它们时,此整数属性的默认值为null.

现在,当我提交表单而不更改此inputtext字段时,即使ui文本字段为空,该字段在bean中也被设置为整数值零.

因为我想跟踪对字段的更改并仅更新配置文件中已更改的那些字段,但这给我带来了问题,因为它导致对所有整数字段的更新.

我正在使用jsf 1.2

解决方案

JSF EL规范规定,在分配数值类型的属性之前,将null转换为0. (请参见有关强制性规则的章节).对此,已经提交了问题,但被规范人员忽略. >

没有真正漂亮的解决方案.最简单的方法是在setter中将0转换回null,但是假定0永远不是有效输入.其他替代方法包括让setter和getter接收/返回非数字类型(例如String),并在setter/getter中进行到Integer的转换.但是,这意味着您将在JSF生命周期中检测到非数字输入太晚,因此您还需要一个附加的验证器/转换器来处理它.

Websphere 7.0.0.11不会将null强制转换为0.

I have integer properties from my bean binded to inputtext UI elements in jsp pages.

initially when they are rendered, default value of this integer properties is null.

Now when i am submitting the form without changing this inputtext fields, this fields are set to integer value zero in bean, even though ui text field is blank.

As i want to track the changes to fields and update only those fields which are changed in configuration files, but this is giving me problem as it results into updates to all integer field.

I am using jsf 1.2

解决方案

The JSF EL specification decrees that null is to be converted to 0 prior to assigning a property of numeric type. (See the chapter on coercion rules). An issue has been filed about this, but is being ignored by the spec people.

There are no really pretty solutions. The easiest is to convert 0 back to null in the setter, but that assumes 0 is never a valid input. Other alternatives include having the setter and getter receive/return a non-numeric type such as String, and do the conversion to/from Integer in the setter/getter. That however means you would detect non-numeric inputs too late in the JSF life cycle, so you also need an additional validator/converter to handle that.

Edit: Websphere 7.0.0.11 doesn't coerce null to 0.

这篇关于jsf:在UI中绑定到inputtext的integer属性在提交时设置为零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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