You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Er...@swissinfo.ch on 2004/01/12 19:23:25 UTC

Validator: Using stand-alone validation fails

Hi

I'm new to this list, so please forgive any stupid questions  :-))

I'm trying to use the Struts Validator for a stand-alone (non-Struts) class.
I used the ValidatorLoader from "Programming Jakarta Struts" (O'Reilly), and
it works up to a point. When I try to validate an e-mail address which is
correct, my code works. However, when I try to validate an invalid e-mail
address, I get the following Exception:


ERROR   - reflection: null [12 Jan 2004 18:05:05,984] @
org.apache.commons.validator.Validator
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:4
54)
	at
org.apache.commons.validator.Validator.validateField(Validator.java:544)
	at
org.apache.commons.validator.Validator.validate(Validator.java:582)
	at
ch.xobix.validation.model.ValidateBp.processObject(ValidateBp.java:105)
	at
ch.xobix.core.model.BaseWithoutConnectionBp.runBp(BaseWithoutConnectionBp.ja
va:38)
	at
ch.xobix.validation.model.ValidationBpImpl.validate(ValidationBpImpl.java:82
)
	at
ch.xobixtest.validation.model.ValidationBpTest.testValidationFramework(Valid
ationBpTest.java:73)
	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 junit.framework.TestCase.runTest(TestCase.java:154)
	at junit.framework.TestCase.runBare(TestCase.java:127)
	at junit.framework.TestResult$1.protect(TestResult.java:106)
	at junit.framework.TestResult.runProtected(TestResult.java:124)
	at junit.framework.TestResult.run(TestResult.java:109)
	at junit.framework.TestCase.run(TestCase.java:118)
	at junit.framework.TestSuite.runTest(TestSuite.java:208)
	at junit.framework.TestSuite.run(TestSuite.java:203)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRu
nner.java:392)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.
java:276)
	at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner
.java:167)
Caused by: java.lang.NullPointerException
	at
org.apache.struts.validator.Resources.getMessageResources(Resources.java:150
)
	at
org.apache.struts.validator.Resources.getActionError(Resources.java:222)
	at
org.apache.struts.validator.FieldChecks.validateEmail(FieldChecks.java:780)
	... 26 more


My validation.xml file looks like this:


<!DOCTYPE form-validation PUBLIC
          "-//Apache Software Foundation//DTD Commons Validator Rules
Configuration 1.0//EN"
          "http://jakarta.apache.org/commons/dtds/validator_1_0.dtd">

<form-validation>
	<global>
	</global>

	<formset>
		<form name="testForm">
			<field property="emailAddress"
depends="required,email" />
		</form>
	</formset>

</form-validation>


and my validator-rules.xml looks like this (excerpt):

...

      <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">
      </validator>
...


However, from what I can see, the Resource file for errors.email can't be
found. Is that right?
I have a resource file ApplicationResources.properties which is in a
package. Could this be the problem? Also, how can I specify a certain
Properties file to the Validator?

Any help is very appreciated!

Eric


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: Validator: Using stand-alone validation fails

Posted by Juan Alvarado <ja...@duocash.com>.
Did you make sure that commons-beanutils is in your path??? I'm pretty  
sure you have to have it.


On Jan 12, 2004, at 1:23 PM, Eric.Lewis@swissinfo.ch wrote:

> Hi
>
> I'm new to this list, so please forgive any stupid questions  :-))
>
> I'm trying to use the Struts Validator for a stand-alone (non-Struts)  
> class.
> I used the ValidatorLoader from "Programming Jakarta Struts"  
> (O'Reilly), and
> it works up to a point. When I try to validate an e-mail address which  
> is
> correct, my code works. However, when I try to validate an invalid  
> e-mail
> address, I get the following Exception:
>
>
> ERROR   - reflection: null [12 Jan 2004 18:05:05,984] @
> org.apache.commons.validator.Validator
> java.lang.reflect.InvocationTargetException
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.ja 
> va:39
> )
> 	at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccesso 
> rImpl
> .java:25)
> 	at java.lang.reflect.Method.invoke(Method.java:324)
> 	at
> org.apache.commons.validator.Validator.validateFieldForRule(Validator.j 
> ava:4
> 54)
> 	at
> org.apache.commons.validator.Validator.validateField(Validator.java: 
> 544)
> 	at
> org.apache.commons.validator.Validator.validate(Validator.java:582)
> 	at
> ch.xobix.validation.model.ValidateBp.processObject(ValidateBp.java:105)
> 	at
> ch.xobix.core.model.BaseWithoutConnectionBp.runBp(BaseWithoutConnection 
> Bp.ja
> va:38)
> 	at
> ch.xobix.validation.model.ValidationBpImpl.validate(ValidationBpImpl.ja 
> va:82
> )
> 	at
> ch.xobixtest.validation.model.ValidationBpTest.testValidationFramework( 
> Valid
> ationBpTest.java:73)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.ja 
> va:39
> )
> 	at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccesso 
> rImpl
> .java:25)
> 	at java.lang.reflect.Method.invoke(Method.java:324)
> 	at junit.framework.TestCase.runTest(TestCase.java:154)
> 	at junit.framework.TestCase.runBare(TestCase.java:127)
> 	at junit.framework.TestResult$1.protect(TestResult.java:106)
> 	at junit.framework.TestResult.runProtected(TestResult.java:124)
> 	at junit.framework.TestResult.run(TestResult.java:109)
> 	at junit.framework.TestCase.run(TestCase.java:118)
> 	at junit.framework.TestSuite.runTest(TestSuite.java:208)
> 	at junit.framework.TestSuite.run(TestSuite.java:203)
> 	at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteT 
> estRu
> nner.java:392)
> 	at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRu 
> nner.
> java:276)
> 	at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestR 
> unner
> .java:167)
> Caused by: java.lang.NullPointerException
> 	at
> org.apache.struts.validator.Resources.getMessageResources(Resources.jav 
> a:150
> )
> 	at
> org.apache.struts.validator.Resources.getActionError(Resources.java: 
> 222)
> 	at
> org.apache.struts.validator.FieldChecks.validateEmail(FieldChecks.java: 
> 780)
> 	... 26 more
>
>
> My validation.xml file looks like this:
>
>
> <!DOCTYPE form-validation PUBLIC
>           "-//Apache Software Foundation//DTD Commons Validator Rules
> Configuration 1.0//EN"
>           "http://jakarta.apache.org/commons/dtds/validator_1_0.dtd">
>
> <form-validation>
> 	<global>
> 	</global>
>
> 	<formset>
> 		<form name="testForm">
> 			<field property="emailAddress"
> depends="required,email" />
> 		</form>
> 	</formset>
>
> </form-validation>
>
>
> and my validator-rules.xml looks like this (excerpt):
>
> ...
>
>       <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">
>       </validator>
> ...
>
>
> However, from what I can see, the Resource file for errors.email can't  
> be
> found. Is that right?
> I have a resource file ApplicationResources.properties which is in a
> package. Could this be the problem? Also, how can I specify a certain
> Properties file to the Validator?
>
> Any help is very appreciated!
>
> Eric
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Re: Validator: Using stand-alone validation fails

Posted by Juan Alvarado <ja...@duocash.com>.
Actually, please disregard my last post. Why don't you just use the  
regular commons-validator package.

import org.apache.commons.validator.*;
import org.apache.commons.validator.util.*;

public boolean isValidEmailAddress(String email){
		
		EmailValidator val = EmailValidator.getInstance();
		return val.isValid(email);
	}

That's what I used when I needed to do an email validation in  
standalone mode. I would be curious if anyone has a  better suggestion.

Thanks


On Jan 12, 2004, at 1:23 PM, Eric.Lewis@swissinfo.ch wrote:

> Hi
>
> I'm new to this list, so please forgive any stupid questions  :-))
>
> I'm trying to use the Struts Validator for a stand-alone (non-Struts)  
> class.
> I used the ValidatorLoader from "Programming Jakarta Struts"  
> (O'Reilly), and
> it works up to a point. When I try to validate an e-mail address which  
> is
> correct, my code works. However, when I try to validate an invalid  
> e-mail
> address, I get the following Exception:
>
>
> ERROR   - reflection: null [12 Jan 2004 18:05:05,984] @
> org.apache.commons.validator.Validator
> java.lang.reflect.InvocationTargetException
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.ja 
> va:39
> )
> 	at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccesso 
> rImpl
> .java:25)
> 	at java.lang.reflect.Method.invoke(Method.java:324)
> 	at
> org.apache.commons.validator.Validator.validateFieldForRule(Validator.j 
> ava:4
> 54)
> 	at
> org.apache.commons.validator.Validator.validateField(Validator.java: 
> 544)
> 	at
> org.apache.commons.validator.Validator.validate(Validator.java:582)
> 	at
> ch.xobix.validation.model.ValidateBp.processObject(ValidateBp.java:105)
> 	at
> ch.xobix.core.model.BaseWithoutConnectionBp.runBp(BaseWithoutConnection 
> Bp.ja
> va:38)
> 	at
> ch.xobix.validation.model.ValidationBpImpl.validate(ValidationBpImpl.ja 
> va:82
> )
> 	at
> ch.xobixtest.validation.model.ValidationBpTest.testValidationFramework( 
> Valid
> ationBpTest.java:73)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.ja 
> va:39
> )
> 	at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccesso 
> rImpl
> .java:25)
> 	at java.lang.reflect.Method.invoke(Method.java:324)
> 	at junit.framework.TestCase.runTest(TestCase.java:154)
> 	at junit.framework.TestCase.runBare(TestCase.java:127)
> 	at junit.framework.TestResult$1.protect(TestResult.java:106)
> 	at junit.framework.TestResult.runProtected(TestResult.java:124)
> 	at junit.framework.TestResult.run(TestResult.java:109)
> 	at junit.framework.TestCase.run(TestCase.java:118)
> 	at junit.framework.TestSuite.runTest(TestSuite.java:208)
> 	at junit.framework.TestSuite.run(TestSuite.java:203)
> 	at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteT 
> estRu
> nner.java:392)
> 	at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRu 
> nner.
> java:276)
> 	at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestR 
> unner
> .java:167)
> Caused by: java.lang.NullPointerException
> 	at
> org.apache.struts.validator.Resources.getMessageResources(Resources.jav 
> a:150
> )
> 	at
> org.apache.struts.validator.Resources.getActionError(Resources.java: 
> 222)
> 	at
> org.apache.struts.validator.FieldChecks.validateEmail(FieldChecks.java: 
> 780)
> 	... 26 more
>
>
> My validation.xml file looks like this:
>
>
> <!DOCTYPE form-validation PUBLIC
>           "-//Apache Software Foundation//DTD Commons Validator Rules
> Configuration 1.0//EN"
>           "http://jakarta.apache.org/commons/dtds/validator_1_0.dtd">
>
> <form-validation>
> 	<global>
> 	</global>
>
> 	<formset>
> 		<form name="testForm">
> 			<field property="emailAddress"
> depends="required,email" />
> 		</form>
> 	</formset>
>
> </form-validation>
>
>
> and my validator-rules.xml looks like this (excerpt):
>
> ...
>
>       <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">
>       </validator>
> ...
>
>
> However, from what I can see, the Resource file for errors.email can't  
> be
> found. Is that right?
> I have a resource file ApplicationResources.properties which is in a
> package. Could this be the problem? Also, how can I specify a certain
> Properties file to the Validator?
>
> Any help is very appreciated!
>
> Eric
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
>

Re: Validator: Using stand-alone validation fails

Posted by David Graham <gr...@yahoo.com>.
It looks like you're trying to use a Struts class
org.apache.struts.validator.FieldChecks to run the validation.  You need
to implement your own validation method and configure it in xml similar to
FieldChecks.

David


--- Eric.Lewis@swissinfo.ch wrote:
> Hi
> 
> I'm new to this list, so please forgive any stupid questions  :-))
> 
> I'm trying to use the Struts Validator for a stand-alone (non-Struts)
> class.
> I used the ValidatorLoader from "Programming Jakarta Struts" (O'Reilly),
> and
> it works up to a point. When I try to validate an e-mail address which
> is
> correct, my code works. However, when I try to validate an invalid
> e-mail
> address, I get the following Exception:
> 
> 
> ERROR   - reflection: null [12 Jan 2004 18:05:05,984] @
> org.apache.commons.validator.Validator
> 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:4
> 54)
> 	at
> org.apache.commons.validator.Validator.validateField(Validator.java:544)
> 	at
> org.apache.commons.validator.Validator.validate(Validator.java:582)
> 	at
> ch.xobix.validation.model.ValidateBp.processObject(ValidateBp.java:105)
> 	at
>
ch.xobix.core.model.BaseWithoutConnectionBp.runBp(BaseWithoutConnectionBp.ja
> va:38)
> 	at
>
ch.xobix.validation.model.ValidationBpImpl.validate(ValidationBpImpl.java:82
> )
> 	at
>
ch.xobixtest.validation.model.ValidationBpTest.testValidationFramework(Valid
> ationBpTest.java:73)
> 	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 junit.framework.TestCase.runTest(TestCase.java:154)
> 	at junit.framework.TestCase.runBare(TestCase.java:127)
> 	at junit.framework.TestResult$1.protect(TestResult.java:106)
> 	at junit.framework.TestResult.runProtected(TestResult.java:124)
> 	at junit.framework.TestResult.run(TestResult.java:109)
> 	at junit.framework.TestCase.run(TestCase.java:118)
> 	at junit.framework.TestSuite.runTest(TestSuite.java:208)
> 	at junit.framework.TestSuite.run(TestSuite.java:203)
> 	at
>
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRu
> nner.java:392)
> 	at
>
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.
> java:276)
> 	at
>
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner
> .java:167)
> Caused by: java.lang.NullPointerException
> 	at
>
org.apache.struts.validator.Resources.getMessageResources(Resources.java:150
> )
> 	at
> org.apache.struts.validator.Resources.getActionError(Resources.java:222)
> 	at
>
org.apache.struts.validator.FieldChecks.validateEmail(FieldChecks.java:780)
> 	... 26 more
> 
> 
> My validation.xml file looks like this:
> 
> 
> <!DOCTYPE form-validation PUBLIC
>           "-//Apache Software Foundation//DTD Commons Validator Rules
> Configuration 1.0//EN"
>           "http://jakarta.apache.org/commons/dtds/validator_1_0.dtd">
> 
> <form-validation>
> 	<global>
> 	</global>
> 
> 	<formset>
> 		<form name="testForm">
> 			<field property="emailAddress"
> depends="required,email" />
> 		</form>
> 	</formset>
> 
> </form-validation>
> 
> 
> and my validator-rules.xml looks like this (excerpt):
> 
> ...
> 
>       <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">
>       </validator>
> ...
> 
> 
> However, from what I can see, the Resource file for errors.email can't
> be
> found. Is that right?
> I have a resource file ApplicationResources.properties which is in a
> package. Could this be the problem? Also, how can I specify a certain
> Properties file to the Validator?
> 
> Any help is very appreciated!
> 
> Eric
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
> 


__________________________________
Do you Yahoo!?
Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes
http://hotjobs.sweepstakes.yahoo.com/signingbonus

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org