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

  • SEARCH
  • Home
  • 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 8108961
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:16:18+00:00 2026-06-06T01:16:18+00:00

I am creating a JSF form where I have an email field. I need

  • 0

I am creating a JSF form where I have an email field. I need to validate the email format and check for uniqueness against DB.

I need to check this when the enduser has entered the email field. If it’s present in the DB, then we need to change the field color to red and otherwise to green. I would like to perform this by ajax.

I have seen examples in PHP, but it’s not clear to me how to do it in JSF.

  • 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-06T01:16:20+00:00Added an answer on June 6, 2026 at 1:16 am

    For general email format validation, you could use <f:validateRegex>.

    <h:inputText id="email" value="#{bean.email}">
        <f:validateRegex pattern="([^.@]+)(\.[^.@]+)*@([^.@]+\.)+([^.@]+)" />
    </h:inputText>
    <h:message for="email" />
    

    To perform validation on blur, add <f:ajax event="blur">.

    <h:inputText id="email" value="#{bean.email}">
        <f:validateRegex pattern="([^.@]+)(\.[^.@]+)*@([^.@]+\.)+([^.@]+)" />
        <f:ajax event="blur" render="m_email" />
    </h:inputText>
    <h:message id="m_email" for="email" />
    

    For unique email validation, implement the JSF Validator interface according its contract.

    @FacesValidator("uniqueEmailValidator")
    public class UniqueEmailValidator implements Validator {
    
        @Override
        public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
            if (value == null) {
                return; // Let required="true" handle, if any.
            }
    
            String email = (String) value;
    
            if (yourUserService.existEmail(email)) {
                throw new ValidatorException(new FacesMessage(
                    FacesMessage.SEVERITY_ERROR, "Email is already in use.", null));
            }
        }
    
    }
    

    and register it by <f:validator>

    <h:inputText id="email" value="#{bean.email}">
        <f:validateRegex pattern="([^.@]+)(\.[^.@]+)*@([^.@]+\.)+([^.@]+)" />
        <f:validator validatorId="uniqueEmailValidator" />
        <f:ajax event="blur" render="m_email" />
    </h:inputText>
    <h:message id="m_email" for="email" />
    

    To change component’s style, you could use EL in style or styleClass attribute.

    <h:inputText id="email" value="#{bean.email}" styleClass="#{component.valid ? (facesContext.postback ? 'ok' : '') : 'error'}">
        <f:validateRegex pattern="([^.@]+)(\.[^.@]+)*@([^.@]+\.)+([^.@]+)" />
        <f:validator validatorId="uniqueEmailValidator" />
        <f:ajax event="blur" render="@this m_email" />
    </h:inputText>
    <h:message id="m_email" for="email" />
    

    You do not necessarily need jQuery for this. It would also have been less robust as jQuery runs at the client side, not the server side (you know, endusers have 100% control over what runs at the client side).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating registration form in JSF and I have field as Active, Inactive
I have a form page that has an inputText field that accepts a date.
I'm creating a composite component in JSF 2..., inside it I have defined a
I'm creating a JSF 2-application and I'm trying to use form validation in the
I recently discovered this very useful Netbeans tutorial for creating a simple JSF 2
I am creating a JSF application. I have some items (e.g. products) from database
We have a JSF 2.0 application running under Glassfish 3.1.1 which has been moved
Background: I have a JSF 2.0 application using MyFaces. Using this application, the users
I'm creating login form using JSF 2.0. Below is the detailed description. When I
I am creating a form in JSF to save a new entity bean. I

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.