【问题标题】:JSF immediate=true to Skip ValidationJSF immediate=true 跳过验证
【发布时间】:2011-03-31 16:07:01
【问题描述】:

commandLink 的immediate="true" 不应该跳过验证吗?单击该链接时,我仍然收到“需要密码”消息,有什么想法吗?

<h:inputSecret id="j_password" autocomplete="off" value="#{authenticationBean.password}" required="true" requiredMessage="Password is Required" />

<p:commandLink action="#{authentication.forgotPassword}" ajax="false">
    <h:outputText value="#{bundle['login.forgotpassword.TEXT']}" immediate="true"/>
</p:commandLink>

【问题讨论】:

    标签: jsf jsf-2


    【解决方案1】:

    您已将其放在&lt;h:outputText&gt; 而不是&lt;p:commandLink&gt;immediate 属性对 UIOutput 组件没有影响(并且在某些环境中也会产生 XML 验证错误),它仅对 UIInputUICommand 组件有影响。将属性移动到&lt;p:commandLink&gt; 组件。

    【讨论】:

      【解决方案2】:

      立即属性不会跳过任何验证。它将组件及其所有事件、验证器等移动到 APPLY_REQUEST 阶段。这样您就有机会在所有其他非立即输入和命令之前处理输入和命令。

      http://www.javacodegeeks.com/2012/01/jsf-and-immediate-attribute-command.html

      如果您想通过立即跳过验证,则必须在立即操作的情况下采取适当的操作,以避免进一步处理输入及其事件,例如 FacesContext 重定向。

      【讨论】:

        【解决方案3】:

        &lt;o:validateBean&gt; 允许开发人员基于每个 UICommand 或 UIInput 组件控制 bean 验证,以及在类级别验证给定 bean。

        该标准仅允许在每个表单或每个请求的基础上进行验证控制(通过在其属性中使用多个标签和条件 EL 表达式),这可能最终出现在样板代码中。 该标准也尽管名称如此,但实际上根本没有任何验证 bean 的工具。

        &lt;o:validateBean disabled="true"/&gt; 该命令将跳过验证

        <p:commandButton 
                    id="refresh"
                    icon="fa fa-refresh"
                    styleClass="refresh-button btn-blue"
                    process="@form"
                    update="phone_1 @form:htmlView">
           <o:validateBean disabled="true"/>
        </p:commandButton>
        

        &lt;o:skipValidators&gt; 标记处理程序允许开发人员在执行 UICommand 或 ClientBehaviorHolder 操作时完全跳过验证。此标记处理程序必须放置在 UICommand 或 ClientBehaviorHolder 组件中(客户端行为持有者组件是支持 &lt;f:ajax&gt; 的组件)。

        <p:commandButton 
              id="refresh"
              icon="fa fa-refresh"
              styleClass="refresh-button btn-blue"
              process="@form"
              update="phone_1 @form:htmlView">
           <o:skipValidators/>
        </p:commandButton>
        

        如果您想了解更多,请看这里:

        http://showcase.omnifaces.org/validators/validateBean http://showcase.omnifaces.org/taghandlers/skipValidators

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2015-03-17
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-02-03
          • 2011-06-18
          相关资源
          最近更新 更多