Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8019469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:23:42+00:00 2026-06-04T21:23:42+00:00

Based on the answer from this question, i understand that if there is an

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T21:23:43+00:00Added an answer on June 4, 2026 at 9:23 pm

    You shouldn’t be doing validation in a backing bean action method, but in a normal Validator.

    E.g.

    <h:inputText value="#{register.email}" required="true" validator="#{emailValidator}" />
    <h:inputSecret binding="#{password}" value="#{register.password}" required="true" />
    <h:inputSecret required="true" validator="confirmPasswordValidator">
        <f:attribute name="password" value="#{password.value}" />
    </h:inputSecret>
    ...
    

    with the #{emailValidator} being something like this:

    @MangedBean
    public class EmailValidator implements Validator {
    
        @EJB
        private UserService userService;
    
        @Override
        public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
            if (value == null) {
                return; // Let required="true" handle.
            }
    
            if (userService.existsEmail((String) value)) {
                throw new ValidatorException(Messages.createError("Email already exists"));
            }
        }
    
    }
    

    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

    @FacesValidator("confirmPasswordValidator")
    public class ConfirmPasswordValidator implements Validator {
    
        @Override
        public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
            Object password = component.getAttributes().get("password");
    
            if (value == null || password == null) {
                return; // Let required="true" handle.
            }
    
            if (!password.equals(value)) {
                throw new ValidatorException(Messages.createError("Password do not match"));
            }
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

UPDATE: Solved. Thanks BusyMark! EDIT: This is revised based on the answer below from
Based the accepted answer to this question I've setup a NetBeans/tomcat environment. In testing
This is a further question based on this answer: How can I implement a
For the following question, I am looking for an answer that is based on
Based on some answers to this question it appears that +alloc does some behind-the-scenes
First I want to make it clear that this is a homework based question.
When researching an answer to a question (based on this answer ) I tried
I can very well understand from this Selectutorial what element/tag based descendant selectors are,
I understand that there's no universal answer to the attribute vs. element debate (and
In this answer to another question , I was told that in scripts you

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.