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";
}
...
}
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With