JSF/Richfaces/A4j ==>组件/字段转换和重新渲染问题
我在 JSF 页面中有一个如下所示的输入字段(映射到支持 bean 上的 BigDecimal),
<h:inputText disabled="#{volumeBean.grossVolumeDisabled}" id="grossVolume" size="10" validateOnExit="true" value="#{volumeBean.enteredGrossVolume}" >
<a4j:support ajaxSingle="true" event="onblur" ignoreDupResponses="true" oncomplete="checkFieldValidation(this)" onsubmit="updateDirty()"/>
</h:inputText>
还有一个 a4j:commandButton 用于“刷新”页面上数据库中的所有数据:
<a4j:commandButton accesskey="T" action="#{volumeBean.revert}" button-type="ajax" disabled="#{volumeBean.revertDisabled}" id="volumeBean_reset" immediate="true" reRender="volumesTable" value="#{msg.button_RESET}"/>
以下是重现我的问题的步骤: 请注意,无论 a4j:support 上是否设置了 reRender 属性,都会发生错误。
以下是重现步骤 - 只是为了进一步澄清:
- 导航到 BigDecimal 输入字段存在的屏幕,
- 在字段中键入 aa (应该是一个数字,但故意放置非数字字符)
- 从该字段中跳出标签,
- 注意报告错误“aa”不是有效的 netVolume
- 单击“重置”按钮
- 所有更改的字段都具有其原始值,除了那些具有非数字的字段输入的数据
- 除非用户手动删除字段中的非数字数据或刷新整个屏幕,否则“坏数据”会持续存在
I have an input field in a JSF Page like the following (maps to BigDecimal on backing bean)
<h:inputText disabled="#{volumeBean.grossVolumeDisabled}" id="grossVolume" size="10" validateOnExit="true" value="#{volumeBean.enteredGrossVolume}" >
<a4j:support ajaxSingle="true" event="onblur" ignoreDupResponses="true" oncomplete="checkFieldValidation(this)" onsubmit="updateDirty()"/>
</h:inputText>
And an a4j:commandButton to "refresh" all the data from the database on the page:
<a4j:commandButton accesskey="T" action="#{volumeBean.revert}" button-type="ajax" disabled="#{volumeBean.revertDisabled}" id="volumeBean_reset" immediate="true" reRender="volumesTable" value="#{msg.button_RESET}"/>
Here are the steps to reproduce my problem:
And please note that the error occurs regardless of whether there is a reRender attribute set on the a4j:support
Here are the steps to reproduce - just to clarify further:
- navigate to the screen where the BigDecimal input field exists
- type aa into the field (should be a number but put non-numeric characters purposely)
- tab off the field
- notice that an error is reported 'aa' is not a valid netVolume
- click on the RESET button
- all of the changed fields have their original values EXCEPT those that have non-numeric data entered
- unless the user manually deletes the non-numeric data in the fields or refreshes the entire screen, the "bad data" sticks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当您进行重置时,您会触发 Ajax 请求,提交整个表单,然后再次收到验证错误。因此该字段仍然具有旧的(不正确的)值。
When you do a reset, you fire an Ajax request, the entire form is submitted and you get validation error again. So the field still has the old (incorrect) value.
尝试将参数
ajaxSingle="true"
添加到按钮。我发现immediate="true"
不足以绕过 ajax 组件的验证。Try adding the parameter
ajaxSingle="true"
to the button. I've found thatimmediate="true"
is not adequate for bypassing validation on ajax components.