应该立即=“真"吗?从未使用过AJAXified JSF 2.0组件? [英] Should immediate="true" never be used when dealing with an AJAXified JSF 2.0 component?

查看:88
本文介绍了应该立即=“真"吗?从未使用过AJAXified JSF 2.0组件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在处理AJAX化的JSF 2.0组件时应该永远不要使用immediate="true"吗?

Should immediate="true" never be used when dealing with an AJAXified JSF 2.0 component?

示例可能是:

如果我想在JSF 2.0页面上实现一个取消"按钮,如果用户单击取消",则不应该运行任何验证,如果该组件是Ajaxified组件,我应该在该组件上设置immediate="true"还是应该指定表单上的任何组件均不应处理?如果是这样,使用组件的AJAXified功能而不是使用immediate="true"的老方法"来实现此功能的方法是什么?

If I want to implement a "Cancel" button on JSF 2.0 page where if the user hits "Cancel", no validations should run, should I set immediate="true" on the component if it is an ajaxified component or should specify that no components on the form should be processed? If so, what is the way to implement this functionality using the AJAXified features of the component and not the "old way" of using immediate="true"?

推荐答案

实际上,自<f:ajax>设置为execute="@this"以来,在取消按钮上使用immediate="true"的目的已无用(已经设置为默认值),以跳过所有以相同形式输入的组件的处理.

Indeed, the purpose of using immediate="true" on a cancel button has become useless since <f:ajax> which you can just set to execute="@this" (which is the default already) to skip the processing of all input components in the same form.

仅当表单已预先提交但由于转换/验证失败而失败时,您才可能遇到问题.如果您按下ajax的取消"按钮并在此后呈现表单,则输入仍将被标记为无效,并且模型值的任何更改都不会反映出来(您可能正在执行entity = new Entity();或使用取消"动作方法进行清除)表格的旧值).与immediate="true"一起使用同步(非ajax)请求时,不会发生此问题.实际上,此问题与immediate="true"没有关系,但与ajax请求的JSF生命周期无关.您基本上需要通过调用 OmniFaces 具有 ResetInputAjaxActionListener 正是出于这个目的.

You may only run into problems when the form was already been submitted beforehand but failed due to a conversion/validation failure. If you hit the cancel button by ajax and render the form thereafter, the inputs would still be marked invalid and any changes in the model value are not reflected (you're probably doing a entity = new Entity(); or something in cancel action method to clear out the old values of the form). This problem does not happen when using a synchronous (non-ajax) request with immediate="true". This issue has actually nothing to do with immediate="true", but with the JSF lifecycle of ajax requests. You basically need to reset the invalidated state of the involved input components by calling EditableValueHolder#resetValue() on the components which are not included in the ajax execute, but are included in the ajax render. OmniFaces has a ResetInputAjaxActionListener for exactly this purpose.

这篇关于应该立即=“真"吗?从未使用过AJAXified JSF 2.0组件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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