commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Graham <grahamdavid1...@yahoo.com>
Subject Re: Validator: Using stand-alone validation fails
Date Mon, 12 Jan 2004 18:34:56 GMT
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


Mime
View raw message