tags:

views:

849

answers:

1

Hi all,

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?

+2  A: 

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"));
Nicholas Smith
Barun
When we encounter this in our projects, we don't put any validators on the page, but handle it all from a submit method on the bean. That's really the cleanest way we've found.
Nicholas Smith
@NicholasI was needlessly worried. The method you said is working fine for displaying multiple validation messages for a single field.
Barun