失败后的JSF2 BeanValidation重置值 [英] JSF2 BeanValidation reset values after failure

查看:132
本文介绍了失败后的JSF2 BeanValidation重置值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的Web应用程序的模块在中间显示一个数据表,在右侧显示所选记录的详细信息.每次用户选择母版表的记录时,我们都会更新详细信息页面并显示所选记录的详细信息.现在我们有以下问题:

The modules of our web application shows a datatable in the center and the detail of the selected record on the right. Every time the user selects a record of the mastertable we update the detail page and show the details of the selected record. Now we have the following problem:

  1. 用户在主表中选择一条记录,并在详细信息区域中显示数据.
  2. 用户修改明细数据并单击保存.
  3. 发生验证(bean验证)错误,用户将看到错误消息(msg).
  4. 用户选择更正主表的另一条记录,而不是纠正错误的输入.
  5. 所有没有错误状态的字段都将使用新记录的数据进行更新.之前错误的字段显示旧数据.旧记录的数据会一直保留,直到用户刷新页面为止.

有什么办法可以解决这个问题?我已经从Primefaces扩展中看到了pe:resetInput组件,但是该组件需要一个UICommand组件才能工作.如果用户选择主表的另一个条目,我需要一个可行的解决方案.

Is there any way to solve this problem? I've seen a pe:resetInput component from Primefaces extensions but this component needs a UICommand component to work. I need a solution that works if the user selects another entry of the mastertable.

推荐答案

您可以使用 OmniFaces ResetInputAjaxActionListener为了这.除了被注册为<f:actionListener>之外,还可以将其全局注册为PhaseListener.

You can use the ResetInputAjaxActionListener of OmniFaces for this. Apart from being registered as a <f:actionListener>, it can also be globally registered as a PhaseListener.

  • ResetInputAjaxActionListener showcase example
  • ResetInputAjaxActionListener API documentation
  • ResetInputAjaxActionListener source code

如果您打算自己掌握它,那么基本上您需要自己编写代码,基本上可以完成以下任务:

If you intend to take it in your own hands, then you basically need to write code yourself which does basically the following things:

  • 在调用动作阶段,获取未由ajax请求执行/处理的待渲染UIInput组件.
  • 在其上调用resetValue()方法.
  • During the invoke action phase, get to-be-rendered UIInput components which are not been executed/processed by the ajax request.
  • Invoke resetValue() method on them.

这篇关于失败后的JSF2 BeanValidation重置值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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