1 Reply Latest reply on Feb 12, 2013 1:40 AM by Siva P

    Validate Email Existance

    Wingman Boby Newbie

      Hi i want to validate the email on server side, how to validate whether the email present in the db, if present show error message.

      and i want to accomplish this before submitting submit button.


      Here is my sample page...........


      <div id="jskLogin">


      <h:form id="fom1">

          <h:panelGrid columns="3">

              <h:outputText value="Email:"/>

              <h:inputText  value="#{userBean.email}" id="email" required="true">



              <h:message for="email"/>

              <h:outputText value="Password:"/>

              <h:inputText  value="#{userBean.password}" id="password">



              <h:message for="password"/>


          <h:commandButton value="Register" action="#{userBean.save}"/>






      Managed Bean..............



      @ManagedBean(name = "userBean")


      public class UserBean implements Cloneable{


                @Size(min = 3, max = 32, message = "UserName is required")

          private String userName;


                @Size(min = 3, max = 32, message = "Email is required")

          private String email;





      can any one post sample code............


      thanks in advance

        • 1. Re: Validate Email Existance
          Siva P Master

          Hi Boby,


          Using ajax u can validate it like below,


                          <h:panelGrid columns="5" border="0"


                              <h:outputText value="#{msg.username}" />

                              <h:outputText value=":" />


                              <h:inputText id="emailField1" value="#urBean.Email}"

                                  required="true" requiredMessage="#{msg.requiredField}"  styleClass="cel"




                                  <f:validateLength  minimum="#{msg.emailMin}" maximum="#{msg.emailMax}">                           


                              <a4j:support event="onblur" actionListener="#{urBean.emailActionListener}"

                                  reRender="p_emailField,eemailField" limitToList="true" />


                              <h:outputText value="*" id ="erroremailField"/>

                              <a4j:outputPanel id="p_emailField" >

                                  <h:message id="eemailField"  for="emailField1" />





          public void emailActionListener(ActionEvent event) {

              log.info("Entering emailActionListener method()......");

              Login login = new Login();



                if (this.selectedUser != null)


                  ********** here check ur email with database you have already email existing or not ****************

                  if (lst.size() > 0) {

                    FacesContext faceContext = FacesContext.getCurrentInstance(); //Instead of doing like this create some boolean variable with false and set as true inside this method

                    FacesMessage facesMessage = new FacesMessage();//if email already exist in the DB means and just render the <h:output text in the screen with color red.

                    facesMessage.setSeverity(FacesMessage.SEVERITY_ERROR); // it shows like error in the screen.       



                    faceContext.addMessage("mainInclude:userAddAloneView:pageForm:emailField", facesMessage);





              catch (Exception ex)






          If you are using richfaces 4 you can alter the code as u like using a4j:ajax and execute ...i hope it works.


          Thanks and Regards,