Reputation: 27455
I wrote a simple JSF-application with two validators to understand JSF process-validation phase. Here're the validators:
@FacesValidator("second")
public class AnotherValidator implements Validator{
public void validate(FacesContext arg0, UIComponent arg1, Object arg2)
throws ValidatorException {
System.out.println("Validation phase, the second");
FacesContext.getCurrentInstance().renderResponse();
throw new ValidatorException(new FacesMessage("The second"));
}
}
and
@FacesValidator("first")
public class ProducerValidator implements Validator{
public void validate(FacesContext arg0, UIComponent arg1, Object arg2)
throws ValidatorException {
System.out.println("Validation phase, the first");
FacesContext.getCurrentInstance().renderResponse();
throw new ValidatorException(new FacesMessage("The first"));
}
}
I thought that if we call the renderResponse
method from a validate
method, the JSF-implementation should skip to the Render response phase. But actually I have the following console output:
Validation phase, the first
Validation phase, the second
In spite of calling renderResponse
from the first validator, the second validator was being invoked anyway... Why? Facelets markup:
<h:inputText value="#{helloBean.p}" converter="conv">
<f:validator validatorId="first"/>
<f:validator validatorId="second" />
</h:inputText>
Upvotes: 1
Views: 1770
Reputation: 1109874
This is specified behavior. From the FacesContext#renderResponse()
javadoc:
Signal the JavaServer faces implementation that, as soon as the current phase of the request processing lifecycle has been completed, control should be passed to the Render Response phase, bypassing any phases that have not been executed yet.
So, it doesn't abruptly abort the current phase as you expected. It will finish the current phase and then advance to the render response phase.
Only, it does that already by default when you throw a ValidatorException
from inside a validator. So, doing it both is unnecessary.
Upvotes: 3