Sébastien Tromp
Sébastien Tromp

Reputation: 612

JSF - Prevent validationFailed when raising a WARN ValidatorException

I have a form which uses validators for its fields. These validators can send back either Severity.SEVERITY_ERROR or Severity.SEVERITY_WARN messages, as illustrated:

if (!isInMainFamily) {
    FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_WARN, "You should make sure to tag your competency in at least one main category", null);
    throw new ValidatorException(message);
}

However, SEVERITY_WARN messages are not blocking for me. They are just a way to tell the user they should correct their input, but won't prevent them from submitting the form and saving their data.

However, it seems that throwing any kind of ValidatorException flags the FacesContext as "validationFailed", which then prevents the submission of the form.

Is there a way to get around this? Or am I misunderstanding something?

Thanks a lot for your help,
Sébastien

Upvotes: 3

Views: 1426

Answers (1)

BalusC
BalusC

Reputation: 1109715

You'd like to add the message to the context instead of throwing it as ValidatorException. It's the exception which marks the input invalid and thus blocks the form submit.

context.addMessage(component.getClientId(), message);

Upvotes: 6

Related Questions