You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by tangy <yi...@wholefoods.com> on 2008/07/11 18:32:38 UTC

@CustomValidator error

Hi all,

I'm new to Struts2 and needed some help troubleshooting an error when I try
to use @CustomValidator.

Here's my setup:

I have the validators.xml file in /WEB-INF/:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE validators PUBLIC
     "-//OpenSymphony Group//XWork Validator Config 1.0//EN"
     "http://www.opensymphony.com/xwork/xwork-validator-config-1.0.dtd">
<validators>
 	<validator name="numericField"
class="xxx.validators.NumberFieldValidator"/>
</validators>

And then I have a class called NumberFieldValidator: 
package xxx.validators;

import com.opensymphony.xwork2.validator.ValidationException;
import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport;

public class NumberFieldValidator extends FieldValidatorSupport {
   // code
}

Then I have the following annotation on a model class:
@CustomValidator(type = "numericField", message = "Price must be a number")
public void setLowPrice(Double lowPrice) {
	this.lowPrice = lowPrice;
}

I am getting the following exception:
2008-07-11 11:22:44 INFO  xwork2.validator.ActionValidatorManagerFactory -
Detected AnnotationActionValidatorManager, initializing it...
Jul 11, 2008 11:22:44 AM org.apache.catalina.core.StandardWrapperValve
invoke
SEVERE: Servlet.service() for servlet default threw exception
java.lang.IllegalArgumentException: There is no validator class mapped to
the name numericField
	at
com.opensymphony.xwork2.validator.ValidatorFactory.lookupRegisteredValidatorType(ValidatorFactory.java:299)


Can anyone tell what I may be missing?

Thanks so much!
-- 
View this message in context: http://www.nabble.com/%40CustomValidator-error-tp18407467p18407467.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: @CustomValidator error

Posted by tangy <yi...@wholefoods.com>.
Yes, that was the problem. Now I have another problem:

My interceptor stack is as follows:
			       <interceptor-ref name="exception"/>
			       <interceptor-ref name="alias"/>
			       <interceptor-ref name="params"/>
			       <interceptor-ref name="servletConfig"/>
			       <interceptor-ref name="prepare"/>
			       <interceptor-ref name="i18n"/>
			       <interceptor-ref name="chain"/>
			       <interceptor-ref name="debugging"/>
			       <interceptor-ref name="profiling"/>
			       <interceptor-ref name="scopedModelDriven"/>
			       <interceptor-ref name="modelDriven"/>
			       <interceptor-ref name="fileUpload"/>
			       <interceptor-ref name="checkbox"/>
			       <interceptor-ref name="staticParams"/>
			       <interceptor-ref name="params">
			         dojo\..*
			       </interceptor-ref>
			       <interceptor-ref name="conversionError"/>
			       <interceptor-ref name="validation">
			           _edit, input, save
			       </interceptor-ref>
			       <interceptor-ref name="workflow">
			           _edit, save
			       </interceptor-ref>

The parameters interceptor is fired before validation as suggested by the
struts 2 defaultStack. So actually before the @CustomValidation on the model
is able to happen, params fires with error:
2008-07-11 13:51:55 ERROR xwork2.interceptor.ParametersInterceptor -
ParametersInterceptor - [setParameters]: Unexpected Exception caught setting
'modelMap[344344].lowPrice' on 'class xxx.action.ItemAction: Error setting
expression 'modelMap[344344].lowPrice' with value
'[Ljava.lang.String;@142d6a9'

Is there any way around this?




newton.dave wrote:
> 
> --- On Fri, 7/11/08, tangy <yi...@wholefoods.com> wrote:
>> I have the validators.xml file in /WEB-INF/:
> 
> AFAIK this file needs to be on the classpath.
> 
> The validation documentation [1] points this out in the "Registering
> Validators" section, stating "The simplest way to do so is to add a file
> name validators.xml in the root of the classpath (/WEB-INF/classes) [...]"
> 
> Dave
> 
> [1] http://struts.apache.org/2.x/docs/validation.html
> 
> 

-- 
View this message in context: http://www.nabble.com/%40CustomValidator-error-tp18407467p18410553.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


Re: @CustomValidator error

Posted by Dave Newton <ne...@yahoo.com>.
--- On Fri, 7/11/08, tangy <yi...@wholefoods.com> wrote:
> I have the validators.xml file in /WEB-INF/:

AFAIK this file needs to be on the classpath.

The validation documentation [1] points this out in the "Registering Validators" section, stating "The simplest way to do so is to add a file name validators.xml in the root of the classpath (/WEB-INF/classes) [...]"

Dave

[1] http://struts.apache.org/2.x/docs/validation.html


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