Disable checks during ajax call

I have a JSF page in which I repeat the list to display <h:dataTable> with some lines containing a check box, some text and a text box. I added checks in such a way that if the chechbox is checked in a line, the user must enter a value in the corresponding text box. In addition, I have a checkbox with the identifier 'copy' over <h:dataTable> , which should copy the value entered in the first text field to all other text fields whose checkboxes are marked in <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> 

In the controller

 public void copyEmail() { //code for copying the first textbox value to all other textboxes } 

The check works fine, but when I check the copy box, the value of the text field is not copied to other text fields. Instead, validation errors are displayed. If I remove the checks from the text box, the copy part is working fine.

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

So, in the summary

I want to disable my checks during ajax call. Is there any way to do this other than immediate=true ?

+1
source share
1 answer

In other words, you want to check the input text field as required only when the checkbox is checked and the true save button is pressed. If so, you need to expand the required attribute with a different check if the save button was clicked. You can check this for the client identifier of the save button on the query parameters map.

eg.

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

Source: https://habr.com/ru/post/982643/


All Articles