views:

30

answers:

1

BeanClass code is:

       public void validEmail(FacesContext context, UIComponent component,
                Object value) throws Exception  
       {

                  //Set the email pattern string
          Pattern p = Pattern.compile(".+@.+\\.[a-z]+");

          //Match the given string with the pattern
          Matcher m = p.matcher(email);

          //check whether match is found 
          boolean matchFound = m.matches();

          if (matchFound)
            System.out.println("Valid Email Id.");
          else
            System.out.println("Invalid Email Id.");
       }

.xhtml Code is:

<h:inputText title="Enter Email Address" value="#{registerBean.email}" id="eMail" required="true" validator="#{registerBean.validEmail}">
<rich:ajaxValidator event="oninputblur"/>

</h:inputText>
<rich:message for="eMail"/>

Exception is:

/Register.xhtml @68,138 validator="#{registerBean.validEmail}": java.lang.NullPointerException

How can i rectify this!

+1  A: 

You need to validate the value which is been passed in as method argument, not the local variable email, simply because it isn't been set yet (it has first to be validated!). It will be set only after validation phase, namely the update model values phase.

So, replace

Matcher m = p.matcher(email);

by

Matcher m = p.matcher(value);
BalusC
sorry, i didn't get you.
azad
how can i get the value from the .xhtml page to my bean?
azad
Help me! Please
azad
Take a break, breathe a few times and reread my answer.
BalusC
i given whole class,Please check it out.
azad
I've given the whole answer. Please check it out. Just modify the variable in the particular code line as demonstrated in the answer.
BalusC
Thank You Very Much!!!!!!!!!!
azad