wood burning stoves*
The moose likes Struts and the fly likes Email validation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Email validation" Watch "Email validation" New topic
Author

Email validation

charu latha
Ranch Hand

Joined: Aug 20, 2002
Posts: 67
I have a jsp page in which i get an email id from the user. I have taken the validation from struts itself.

My jsp page is like this:

<td width="25%"><b><html:text property="emailID" /></b></td>

I have written in my validator.xml the follwing lines:

<field property="emailID" depends="required,email">
<arg0 key="registerForm.emailid" />
</field>

I know i have to check the email in my form bean but i am unable to decipher how. Its something basic i know but i am really stumped how.

My validation for required in the form bean i have written as shown below:

if (getEmailID() == null || getEmailID().length() < 1){
System.out.println ("if loop emailid name is " + emailID);
errors.add("emailID", new ActionError("errors.registerForm.emailid.required"));
}

Now for the email validation how should i do it in the form bean. Am i thinking about this the wrong way?

Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
If you're using the validator plugin, you shouldn't need to code anything into your FormBean -- the 'email' validation is built-in into the framework.


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Marc Winder
Greenhorn

Joined: Nov 26, 2003
Posts: 6
Lasse is right but check your validator-rules.xml and make sure it includes the email validator definition which should include the "validateEmail" JS function. If so, you should be all set.
charu latha
Ranch Hand

Joined: Aug 20, 2002
Posts: 67
Ok i checked my validator rules and it has the function but for some reason my email never gets checked. any ideas?

Prasanna Puttappa
Ranch Hand

Joined: Jul 21, 2003
Posts: 54
1. Is your form bean extending org.apache.struts.validator.ValidatorForm ?
2. Is property name same in your xml file and formbean class ??

- Prasanna


~Prasanna (SCJP5.0, SCWCD5)
charu latha
Ranch Hand

Joined: Aug 20, 2002
Posts: 67
hi,

thanks for your post. nope my bean extends actionform and not validatorform.

 
wood burning stoves
 
subject: Email validation