Reputation: 1901
I have written a PhaseListener
in which I am checking for the Validations phase. Is there a way using which I can check in the afterPhase()
method of listener that validation has failed and the next phase after the Validation phase will be Render Response phase.
Upvotes: 0
Views: 6587
Reputation: 1109745
If you're on JSF 2.0, just use FacesContext#isValidationFailed()
to check it.
if (context.isValidationFailed()) {
// Validation has failed.
}
You can by the way also check for it in the view side as follows:
<h:panelGroup rendered="#{facesContext.validationFailed}">
<p>Validation has failed.</p>
</h:panelGroup>
Upvotes: 6
Reputation: 1966
Use the maximum severity for error in the FacesContext
Severity maximumSeverity = FacesContext.getCurrentInstance().getMaximumSeverity();
boolean validationFailed=false;
if (maximumSeverity != null
&& (maximumSeverity==FacesMessage.SEVERITY_ERROR || maximumSeverity
==FacesMessage.SEVERITY_FATAL)) {
validationFailed=true;
}
If the value of the validationFailed is true then there are some error messages present.
Upvotes: 3
Reputation: 5792
How about using FacesContext, can you check if there are any enqueued messages? Eg.
FacesContext context = FacesContext.getCurrentInstance();
Iterator<FacesMessage> messages = context.getMessages();
hope that helps.
Upvotes: 1