File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

validate fields without extending ActonSupport

 
Fabiano Souza
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello guys,

Need a help from you.. I'm having problem in validating input data in a Struts 2 application. I'm using a class with fields that match fields in form but I don't want this class to extends ActionSupport and I want this class to use struts annotations to validate fields.. this class will only be used to store and validate input fields.. My doubt is: is there a way to make this work in a alternative way than extends ActionSupport?

waiting for your comments..

Thanks in advance!

Fabiano
 
Joe Ess
Bartender
Posts: 9214
9
Linux Mac OS X Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no requirement to implement ActionSupport for Struts 2 actions. I would assume to use validation one would have to implement the Validateable and ValidationAware interfaces.
 
Fabiano Souza
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what I am trying to do is to put all validation rules in the specific object field using annotations... I've heard I can do this using @VisitorFieldValidator but I`m not able to make it work.
 
Joe Ess
Bartender
Posts: 9214
9
Linux Mac OS X Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've never used it, but the documentation states that the annotation needs to be used with the ModelDriven pattern. Are you doing so?
 
Fabiano Souza
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not familiar with ModelDriven but I will try... what I was wondering is.. what if I have a nested object with validations annotations inside another nested object.. will this work? if it works that will be a good code reuse for me..
 
Joe Ess
Bartender
Posts: 9214
9
Linux Mac OS X Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If by "nested" you mean subclass and superclass, it could work, but the subclass would have to specifically invoke super.validate().
 
Fabiano Souza
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sorry by "nested" I mean.. imagine I have a class Document which has the validate annotation for its fields.. this class Document is an attribute of class User which also has its validate annotations.. now in the class that extends ActionSupport I have an User attribute.. so in the form I have the fiels for document and user and I want to invoke their class validation automatically... if this work will be a great code reuse..
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic