views:

163

answers:

1

I have checked the validator source code and the examples of user-defined rule in the book "Jakarta Struts Live." When people define validator rules in validator-rules.xml, the following declaration for "methodParams" seems to be the only choice:

methodParams="java.lang.Object,
                   org.apache.commons.validator.ValidatorAction,
                   org.apache.commons.validator.Field,
                   org.apache.struts.action.ActionMessages,
                   org.apache.commons.validator.Validator,
                   javax.servlet.http.HttpServletRequest"

Okay, my question is that if this is the only possibility, why do we bother to specify it? Or please provide me with an example if this declaration is not the only choice.

Thanks.

A: 

Please take a look at this link: http://struts.apache.org/1.1/userGuide/dev_validator.html It says:

The methodParams attribute takes a comma separated list of class names. The method attribute needs to have a signature complying with the above list. The list can be comprised of any combination of the following:

java.lang.Object - Bean validation is being performed on. org.apache.commons.validator.ValidatorAction - The current ValidatorAction being performed. org.apache.commons.validator.Field - Field object being validated. org.apache.struts.action.ActionErrors - The errors objects to add an ActionError to if the validation fails. javax.servlet.http.HttpServletRequest - Current request object. javax.servlet.ServletContext - The application's ServletContext. org.apache.commons.validator.Validator - The current org.apache.commons.validator.Validator instance. java.util.Locale - The Locale of the current user.

It seems that "methodParams" can be any combination of the listed types, and Strurs Validator Plugin will inject the instances into the validation function call accordingly.

"methodParams" can be changed.

Winston Chen