简体   繁体   English

在处理AJAXified JSF 2.0组件时,是否应该立即使用immediate =“true”?

[英]Should immediate=“true” never be used when dealing with an AJAXified JSF 2.0 component?

Should immediate="true" never be used when dealing with an AJAXified JSF 2.0 component? 在处理AJAXified JSF 2.0组件时,是否应该immediate="true"

The example might be: 示例可能是:

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? 如果我想在JSF 2.0页面上实现“取消”按钮,如果用户点击“取消”,则不应运行任何验证,如果它是ajaxified组件,或者应该指定no,我应该在组件上设置immediate="true"吗?应该处理表单上的组件? 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" ? 如果是这样,使用组件的AJAXified功能实现此功能的方法是什么,而不是使用immediate="true"的“旧方法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. 实际上,在取消按钮上使用immediate="true"的目的已经变得无用了,因为<f:ajax>你可以设置为execute="@this" (这是默认的)跳过所有输入的处理组件形式相同。

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). 如果您通过ajax点击取消按钮并在此后呈现表单,则输入仍将被标记为无效,并且模型值中的任何更改都不会反映出来(您可能正在执行entity = new Entity();或取消操作中的某些内容清除表格旧值的方法)。 This problem does not happen when using a synchronous (non-ajax) request with immediate="true" . 使用immediate="true"的同步(非ajax)请求时不会发生此问题。 This issue has actually nothing to do with immediate="true" , but with the JSF lifecycle of ajax requests. 这个问题实际上与immediate="true"无关,而是与JSF生命周期的ajax请求有关。 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 . 您基本上需要通过在未包含在ajax execute的组件上调用EditableValueHolder#resetValue()来重置所涉及的输入组件的无效状态,但是它们包含在ajax render OmniFaces has a ResetInputAjaxActionListener for exactly this purpose. OmniFaces有一个ResetInputAjaxActionListener用于此目的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM