• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

struts2:Validate specific method in an action(through xxx-validation.xml or Vlidation Annotation)

 
Ivy chen
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In an action, there will be lots of methods,"struts2 docs" tells me i can override validateXxx() to validate the specific method in the action.

And also we can use "actionClass-validation.xml" or Vlidation Annotation to validate methods in the action.

question:Can I use these "actionClass-validation.xml" or "Vlidation Annotation" to validate the specific method in the action?

------------------------------------------------

For example:
in the "myStrutsAction",i have 2 methods:"barRegist()" and "fooLogin()", Three parameters:"name","password","age";

in method"barRegist()",i will use these three parameters to regist an User,that i should validate the whole parameters.

in method"fooLogin()",i just only use "name" and "password" for User login, i just have to validate "name" and "password".

----------------------------------------------

Then how can i config the "actionClass-validation.xml" or "Vlidation Annotation" to validate the specific method?

i know "Client Validation" can do this,it just like a basic validation, it can not satisfy my requirement and it can not set a "message".

waiting for your answer~Thanks!
 
Joe Ess
Bartender
Posts: 9312
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ivy chen wrote:
question:Can I use these "actionClass-validation.xml" or "Vlidation Annotation" to validate the specific method in the action?

Yes. According to the validation documentation validator configuration files can be named:

* <actionClass>-validation.xml
* <actionClass>-<actionAlias>-validation.xml

With the latter example specific to a particular alias/action method
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic