Reputation: 513
I have run into a blocking scenario and need help. The problem is basically this: There is a field on the page which is attached to a validator. This validator in turn validates other fields in particular relation and should throw error messages for all the related fields that have failed validation.
So basically I want a single validator exception to contain multiple facesmessage which should be displayed on the page a list. Is there any method to do the same. From my understanding each ValidatorException can be attached with a single FacesMessage. So I tried out by giving "\n" and even "" in between different messages in a single FacesMessage string to display the messages in new lines but it does not work. Can anyone please help me out?
Upvotes: 1
Views: 3816
Reputation: 2596
How about adding the faces messages directly, for example if you had 3 text input fields you wanted to display a message on, and had them bound as input1, input2 and input3:
FacesContext.getCurrentInstance().addMessage(
input1.getClientId(FacesContext.getCurrentInstance()),
new FacesMessage(FacesMessage.SEVERITY_ERROR,
"Validation Failed", "Validation Failed"));
FacesContext.getCurrentInstance().addMessage(
input2.getClientId(FacesContext.getCurrentInstance()),
new FacesMessage(FacesMessage.SEVERITY_ERROR,
"Validation Failed", "Validation Failed"));
FacesContext.getCurrentInstance().addMessage(
input3.getClientId(FacesContext.getCurrentInstance()),
new FacesMessage(FacesMessage.SEVERITY_ERROR,
"Validation Failed", "Validation Failed"));
Upvotes: 3