在ajax调用期间关闭验证 [英] Switch off Validations during ajax call

查看:52
本文介绍了在ajax调用期间关闭验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JSF页面,在其中迭代一个列表以显示<h:dataTable>,其中某些行包含复选框,一些文本和一个文本框.我添加了验证,以便如果选中了行中的复选框,则用户必须在相应的文本框中输入值.另外,我在<h:dataTable>上方有一个ID为'copy'的复选框,该复选框会将在第一个文本框中输入的值复制到所有其他在<h:dataTable>中被选中的文本框中. /p>

I have a JSF page in which I am iterating a list to display the <h:dataTable> with some rows containing checkbox, some text and a textbox. I have added validations such that if a chechbox in a row is checked, the user must enter value inside the corresponding textbox. Also, I have a checkbox with id 'copy' above the <h:dataTable> which should copy the value entered in the first textbox to all other textboxes whose checkboxes are checked within the <h:dataTable>.I used an ajax call for the same.

 <h:form prependId="false" id="form">
 <h:selectBooleanCheckbox value="#{bean.copy}" id="copy">
        <p:ajax process="#{bean.mailId}"
            event="change" partialSubmit="true" 
            listener="#{Controller.copyEmail()}"
            update="rm">
        </p:ajax>
    </h:selectBooleanCheckbox>

   <h:dataTable id="rm" width="100%" cellspacing="4"
        value="#{controller.alertTriggers}" var="alt"
            columnClasses="c1,c2,c3,c4">  
            <h:column>
                  <h:selectBooleanCheckbox value="#{alt.checkValue}" id="checkbox" binding="#{checkbox}"/>
               </h:column>
                <h:column>
                   <h:outputText value="#{alt.id}" />                                       
                </h:column>
                <h:column>
                  <h:outputFormat value="#{alt.msg1}" />                              
                </h:column>
                <h:column>                                              
                     <h:message for="emailID" id="email" styleClass="validation-error"/>
                     <h:inputText value="#{alt.mailId}" id="emailID" style="width: 87%;" required="#{checkbox.value}" requiredMessage="Enter the value"/>

                </h:column>                                         

  </h:dataTable>                                          
 </h:form>  

在控制器中

public void copyEmail() {

//code for copying the first textbox value to all other textboxes

}

验证工作正常,但是当我选中 copy 复选框时,文本框值不会复制到其他文本框.而是显示验证错误.如果我从文本框中删除验证,则复制部分可以正常工作.

The Validation works fine, but when i check the copy checkbox, the textbox value do not get copied to the other textboxes. Instead, validation errors are shown. If I remove validations from the textbox, the copying part works fine.

我尝试将immediate=true用于我的Ajax调用,但是<h:dataTable>内的复选框的值未在控制器内更新.

I tried using immediate=true for my ajax call but then the value of the checkboxes inside the <h:dataTable> are not updated within the controller.

所以,总结

我想在ajax调用期间关闭我的验证.除了immediate=true之外,还有其他方法吗?

I want to switch off my validations during the ajax call. Is there any way to do that other than immediate=true?

推荐答案

在换句话说,要验证输入文本字段为仅当复选框被选中真节省按下按钮?如果是这样,则需要再次检查required属性是否已按下保存按钮.您可以通过在请求参数映射中是否存在保存按钮的客户端ID来进行检查.

In other words, you want to validate the input text field as required only when the checkbox is checked and the true save button is pressed? If so, then you'd need to extend the required attribute with another check if the save button is been pressed. You can check that by the presence of the save button's client ID in the request parameter map.

例如

<h:selectBooleanCheckbox binding="#{checkbox}" .../>
...
<h:inputText ... required="#{checkbox.value and not empty param[save.clientId]}" />
...
<p:commandButton binding="#{save}" ... />

这篇关于在ajax调用期间关闭验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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