commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eric.Le...@swissinfo.ch
Subject RE: Validator: Using stand-alone validation fails
Date Tue, 13 Jan 2004 09:56:46 GMT
Hmmm... I do have the commons-validator.jar in my path, but looking at it in
Eclipse shows me only a package org.apache.commons.validator.
Downloading the latest commons-validator.jar doesn't show me any more...
That is, I can't instantiate the EmailValidator, since it's unknown.

Eric

-----Original Message-----
From: Juan Alvarado [mailto:jalvarado@duocash.com]
Sent: Montag, 12. Januar 2004 19:42
To: Jakarta Commons Users List
Subject: Re: Validator: Using stand-alone validation fails


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
>
>


---------------------------------------------------------------------
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