Based on the answer from this question, i understand that if there is an error, EJB will throw an exception which will be catch in the backing bean and backing bean will show user an error message based on exception its catch.
My question is, what if theres more than one error? How can i show multiple error message to the user, while the EJB can only throw one exception at a time?
For example, at registration form user will need to input email address, name, password, and re-password, and must not be null. If all the data is valid but the given email address is already exist, EJB will throw EntityExistException and the user will be notified that email address is already registered. What if theres multiple error like password and re-password not match and the name is empty? And i want to show these two error to the user. What exception should EJB throw? What approach i can take to achieve this?
Note: the validation must be in EJB
You shouldn't be doing validation in a backing bean action method, but in a normal
Validator
.E.g.
with the
#{emailValidator}
being something like this:Note that the EJB shouldn't throw an exception here. It should only do that when there's a fatal and unrecoverable error such as DB down or wrong table/column definitions.
And the
confirmPasswordValidator
being something like this