Accessing request parameters from inside validator?

Re-read your question and I am going to interpret it as this: You would like to write a custom validator that checks that if a city field exists, the country field is equal to 'US So, I would look at going about this in the following fashion: First create a validator interface: Documented @ValidatorClass(value=CountryEqualsUSValidator. Class) @Target(ElementType. TYPE) @Retention(RetentionPolicy.

RUNTIME) public @interface CountryEqualsUS { String message() default "The country should be US for the city provided"; } Then create a validator class: public class CountryEqualsUSValidator implements Validator { public void initialize(CountryEqualsUS arg0) { } public boolean isValid(Object value) { if(value! = null && value instanceof YourBeanClass) { YourBeanClass yourBeanClass = (YourBeanClass) value; if(/*some test logic here*/) { return true; else { return false; } } return false; } } Then on the class that you want to validate: CountryEqualsUS public class YourBeanClass { ... } Then, finally, on your controller/action class, when the form is submitted, the city is a value for which you want to check the country, add this method and call it: public boolean doValidation(YourBeanClass yourBeanClass) { ClassValidator requestValidator = new ClassValidator(yourBeanClass.getClass()); InvalidValue validationMessages = requestValidator. GetInvalidValues(yourBeanClass); if (validationMessages!

= null && validationMessages. Length > 0) { for (int I = 0; I.

Re-read your question and I am going to interpret it as this: "You would like to write a custom validator that checks that if a city field exists, the country field is equal to 'US'" So, I would look at going about this in the following fashion: First create a validator interface: @Documented @ValidatorClass(value=CountryEqualsUSValidator. Class) @Target(ElementType. TYPE) @Retention(RetentionPolicy.

RUNTIME) public @interface CountryEqualsUS { String message() default "The country should be US for the city provided"; } Then create a validator class: public class CountryEqualsUSValidator implements Validator { public void initialize(CountryEqualsUS arg0) { } public boolean isValid(Object value) { if(value! = null && value instanceof YourBeanClass) { YourBeanClass yourBeanClass = (YourBeanClass) value; if(/*some test logic here*/) { return true; else { return false; } } return false; } } Then on the class that you want to validate: @CountryEqualsUS public class YourBeanClass { ... } Then, finally, on your controller/action class, when the form is submitted, the city is a value for which you want to check the country, add this method and call it: public boolean doValidation(YourBeanClass yourBeanClass) { ClassValidator requestValidator = new ClassValidator(yourBeanClass.getClass()); InvalidValue validationMessages = requestValidator. GetInvalidValues(yourBeanClass); if (validationMessages!

= null && validationMessages. Length > 0) { for (int I = 0; I.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions