Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignore validation on commandButton press

Tags:

jsf

primefaces

I have page in which I edit some entity. That page has two command buttons. One is "Back" and one is "Save" and also on that page I have form with input fields (idInputSubject). Some of them are required, some are not.

How can I ensure that we I press "Back" button (cancel editing and go back) validation will be ignored, which is not the case now. Now, when I press either "Back" or "Save" button validation's messages appear if I did't fill required filed with the correct values (idInputSubject).

Both "Back" and "Save" buttons are in the same form:

<h:form id="idFormMeasureDetail" styleClass="bodyForm" prependId="false">
   ...
   <p:commandButton value="#{contentMB.msg.label_back.value}"
        action="#{chooseMeasureControllerMB.aSearch}"
        rendered="#{detailMeasureMB.navigation eq 0}" ajax="false"
        icon="ui-icon-arrowreturnthick-1-w"/>
   <p:commandButton value="#{contentMB.msg.button_save.value}" ajax="false" 
        icon="ui-icon-disk" actionListener="#{detailMeasureControllerMB.alApplyChanges}" 
                    title="#{contentMB.msg.tip_Apply.value}" />

   ...
   <p:inputTextarea id="idInputSubject" value="#{detailMeasureMB.measure.aufgabe}"
    readonly="#{!userSessionMB.supervisor and !detailMeasureMB.isCreator}"
    required="#{globalSessionMB.globalWebOptionsMap['MMRequiredSubject'].propvalue}"
            title="#{contentMB.msg.tip_Betreff.value}"
            autoResize="false" style="width:100%;" >
   </p:inputTextarea>
   <p:message id="inputSubjectMsg" for="idInputSubject" display="icon" />
   ...

</h:form>

ChooseMeasureControllerMB:

@ManagedBean(name = "chooseMeasureControllerMB")
@RequestScoped
public class ChooseMeasureControllerMB extends BaseMeasureControllerMB {
...
public String aSearch() {
            ...
    // navigate to target-page
    return "/pages/mm/showMeasuresList.xhtml?faces-redirect=true";
}
...
}
like image 567
Nikola Avatar asked Aug 08 '12 11:08

Nikola


1 Answers

If you want prevent/skip validation on certain button click use

immediate="true" on that specific button

For a good explanation about the immediate="true" read the following BalusC answer

And here a nice diagram that shows how imemdiate="true works"

like image 72
Daniel Avatar answered Nov 07 '22 16:11

Daniel