简体   繁体   English

为什么将“立即”属性添加到EditableValueHolders?

[英]Why was “immediate” attribute added to the EditableValueHolders?

Initially immediate flag was only intended for ActionSource interface. 最初immediate标志仅用于ActionSource接口。 But later on it was added to the EditableValueHolder interface also. 但后来它也被添加到EditableValueHolder界面。 What was the reason for design decision ? 设计决策的原因是什么?

It's to be used to prioritize validation on several EditableValueHolder components in the same form. 它用于以相同的形式对几个EditableValueHolder组件的验证进行优先级排序。

Imagine a form containing input components with immediate="true" as well as input components without this attribute. 想象一下包含immediate="true"输入组件的表单以及没有此属性的输入组件。 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. 这在具有复杂验证规则的表单中特别有用,其中在(立即)组件X的验证失败时验证组件Y没有意义。

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. 当在同一表单的命令按钮上与immediate="true"结合使用时,这将导致完全跳过所有非立即输入。 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". 一个好的真实世界的例子是一个登录表单,其中包含2个字段“username”和“password”,其中required="true"和2个按钮:“login”和“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. 您可以在“用户名”字段上输入immediate="true" ,并在“密码忘记”按钮上跳过密码字段上的required="true"检查。

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. 在黑暗的JSF 1.x年龄中, immediate="true"也经常(ab)与valueChangeListenerFacesContext#renderResponse()一起用作hack,而不仅仅是在级联下拉列表中。 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. 到目前为止,它使开发人员能够在更改<h:selectOneMenu>执行支持bean方法,而不会验证同一表单中的所有其他输入。 But these days, with the ajax awesomeness, this hack is unnecessary. 但是现在,由于ajax很棒,这种黑客行为是不必要的。 You can find a concretre example of this case at the bottom of our <h:selectOneMenu> wiki page . 您可以在<h:selectOneMenu> wiki页面的底部找到此案例的concretre示例。

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. 这些天, immediate="true"仍然经常(ab)使用,以便有一个完全绕过所有其他输入的特定按钮,例如“神形式”反模式中的注销按钮(其中所有内容都被抛在一起)在一个巨大的<h:form> ),或一个错误提交表单的取消按钮。 Such a button would break when you start to actually need the immediate="true" the right way on one of the inputs. 当你开始在其中一个输入上以正确的方式实际需要immediate="true"时,这样的按钮就会中断。 You'd better put such a logout button in its own form, or to change it to process only itself ( process="@this" in PrimeFaces). 您最好以自己的形式放置这样的注销按钮,或者将其更改为仅process="@this"它自己(在PrimeFaces中为process="@this" )。 And you'd better change such a cancel button to just refresh the page synchronously by <h:button value="Cancel" /> . 并且您最好更改这样的取消按钮,以便通过<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. 如果表单绑定到请求/视图范围bean并且动态页面上禁用了浏览器缓存,则此方法可以正常工作。

See also: 也可以看看:

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

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