为什么要“立即"处理?属性添加到EditableValueHolders? [英] Why was "immediate" attribute added to the EditableValueHolders?

查看:88
本文介绍了为什么要“立即"处理?属性添加到EditableValueHolders?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最初,immediate标志仅用于ActionSource接口.但是后来它也被添加到了EditableValueHolder接口.设计决定的原因是什么?

Initially immediate flag was only intended for ActionSource interface. But later on it was added to the EditableValueHolder interface also. What was the reason for design decision ?

推荐答案

它用于对具有相同形式的几个EditableValueHolder组件的验证进行优先级排序.

It's to be used to prioritize validation on several EditableValueHolder components in the same form.

想象一下一个表单,其中包含带有immediate="true"的输入组件以及没有此属性的输入组件.立即输入将在申请请求值"阶段(比通常情况早一个阶段)期间得到验证.非直接输入将在验证阶段(通常是阶段)进行验证.如果对至少一个立即输入的验证失败,那么非立即输入将根本不会被转换/验证,因此不会生成任何转换/验证错误消息.这在具有复杂验证规则的表单中特别有用,在这种情况下,对于(立即)组件X的验证仍然失败时,对组件Y进行验证就没有意义.

Imagine a form containing input components with immediate="true" as well as input components without this attribute. The immediate inputs will be validated during apply request values phase (which is one phase earlier than usual). The non-immediate inputs will be validated during validations phase (which is the usual phase). If validation fails for at least one of the immediate inputs, then the non-immediate inputs won't be converted/validated at all and thus won't generate any conversion/validation error messages. This is particularly useful in forms with complex validation rules where it doesn't make sense to validate component Y when validation for (immediate) component X has failed anyway.

当以相同形式与命令按钮上的immediate="true"组合使用时,这将导致所有非立即输入被完全跳过.一个真实的好例子是一个登录表单,其中包含2个字段用户名"和密码",并带有required="true"和2个按钮:登录"和忘记密码".您可以将immediate="true"放在用户名"字段上,并在忘记密码"按钮上跳过对密码字段的required="true"检查.

When used in combination with immediate="true" on a command button in the same form, this will cause all non-immediate inputs being completely skipped. A good real world example is a login form with 2 fields "username" and "password" with required="true" and 2 buttons: "login" and "password forgotten". You could put immediate="true" on the "username" field and the "password forgotten" button to skip the required="true" check on the password field.

在黑暗的JSF 1.x时代,immediate="true"也经常与(c10)和FacesContext#renderResponse()一起用作(hack)骇客,在级联的下拉列表中使用的次数更多.长话短说,这是旧博客文章.到目前为止,它使开发人员可以在更改<h:selectOneMenu>时执行后备bean方法,而无需验证所有相同形式的其他输入.但是这些天来,由于ajax的出色表现,这种破解是不必要的.您可以在我们的<h:selectOneMenu> Wiki页面的底部找到此案例的具体示例.

In the dark JSF 1.x ages, the immediate="true" was also often (ab)used as a hack in combination with valueChangeListener and FacesContext#renderResponse(), more than often in cascading dropdown lists. Long story short, here's an old blog article on that. To the point, it enables developers to execute a backing bean method on change of a <h:selectOneMenu> without that all other inputs in the same form are been validated. But these days, with the ajax awesomeness, this hack is unnecessary. You can find a concretre example of this case at the bottom of our <h:selectOneMenu> wiki page.

这几天,immediate="true"仍然经常被使用,以使特定的按钮完全绕开所有其他输入,例如上帝形式"反模式中的注销按钮(由此 被一起放在一个巨大的<h:form>中),或者是一个取消提交表单的取消按钮.当您开始真正需要正确使用immediate="true"之一输入时,此类按钮将中断.您最好以自己的形式放置这样的注销按钮,或将其更改为仅自行处理(PrimeFaces中的process="@this").而且,您最好更改这样的取消按钮,以通过<h:button value="Cancel" />同步刷新页面.如果表单与请求/视图范围的bean绑定并且浏览器缓存为

These days, the immediate="true" is still often (ab)used in order to have a specific button which completely bypasses all other inputs, such as a logout button in a "God-form" antipattern (whereby everything is been thrown together in a huge <h:form>), or a cancel button which incorrectly submits the form. Such a button would break when you start to actually need the immediate="true" the right way on one of the inputs. You'd better put such a logout button in its own form, or to change it to process only itself (process="@this" in PrimeFaces). And you'd better change such a cancel button to just refresh the page synchronously by <h:button value="Cancel" />. This works fine if the form is tied to a request/view scoped bean and browser caching is disabled on dynamic pages.

  • Should immediate="true" never be used when dealing with an AJAXified JSF 2.0 component?
  • Trying to understand immediate="true" skipping inputs when it shouldn't

这篇关于为什么要“立即"处理?属性添加到EditableValueHolders?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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