This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
I use Struts 1.1 with Tomcat 5.0 as my webserver. My JSP has 3 text boxes. All three can't be left empty and one of them is accepts an email address. I want this text box to be validated for "email" and "required". Validation works for 'required', but doesnt work for 'email'. I am probably missing something here. Nothing happens abt the email check, it merely goes onto the next Action class - if the text box is not empty. Please have a look at my code: Validation.xml:
And in ApplicationResources.properties:
I checked validator_rules.xml. It does contain scripts to validate email. What am I missing here? Please help. Thanks -- $uDhA
All that you have posted up here is correct way to do it and it should be working, not sure why it is not. One thing comes to mind though. I am sure i am just being paranoid but still can you check if: <validator name="email" classname="org.apache.struts.validator.FieldChecks" method="validateEmail" methodParams="java.lang.Object, org.apache.commons.validator.ValidatorAction, org.apache.commons.validator.Field, org.apache.struts.action.ActionErrors, javax.servlet.http.HttpServletRequest" depends="" msg="errors.email"> is there in your validator-rules.xml Sandy
I had the same problem with the email validation not working, and I found the following in tomcat's logs:
java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at org.apache.commons.validator.Validator.validateFieldForRule(Validator.java:454) at org.apache.commons.validator.Validator.validateField(Validator.java:544)
at java.lang.Thread.run(Thread.java:534) Caused by: java.lang.NoClassDefFoundError: org/apache/oro/text/perl/Perl5Util at org.apache.commons.validator.GenericValidator.isEmail(GenericValidator.java:420) at org.apache.struts.validator.FieldChecks.validateEmail(FieldChecks.java:779) ... 41 more
I put the oro.jar in my webapp's lib directory, restarted, and email validation worked.