-1

I'm validating data selected in a dropdown - ice:selectOneMenu on a form. On the valueChangeListener. I have validation which adds an error message:

FacesContext.getCurrentInstance().addMessage(fieldId, 
    new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, msg));

The validation works on the Bean and the error message is displayed to the user but when the "Save" commandbutton is clicked, the page continues the confirm page when it's suppose to stay on the capture page until the correct value is selected in the dropdown.

Why does the page continue to confirm the page?

Dani
  • 3,744
  • 4
  • 27
  • 35
Vuzi
  • 185
  • 2
  • 4
  • 13
  • Are you throwing a `ValidatorException` when the validation fails ? – Andy Jul 15 '13 at 17:16
  • Please post a bit of your code in relate to how your validator relative to your submit button. Does your validator call when u call submit button? Does your submit button does form submission or is it only do ajax partial request? – Thang Pham Jul 16 '13 at 04:35
  • you have to use validator and throw validatorException – Vishnudev K Feb 10 '15 at 09:44

1 Answers1

1

When validation fails, you have to throw an ValidatorException so that the input can be treated as invalid one. That's most likely the cause. Instead of

FacesContext.getCurrentInstance().addMessage(fieldId,
                new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, msg));

do

throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, msg));
Andy
  • 5,900
  • 2
  • 20
  • 29
  • 1
    Noted should be that this only works when you're using a `Validator` for the validation job. OP, however, was abusing a `valueChangeListener` for the validation job. – BalusC Dec 29 '14 at 09:34