aspose file tools*
The moose likes Struts and the fly likes validate fields without extending ActonSupport Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "validate fields without extending ActonSupport" Watch "validate fields without extending ActonSupport" New topic
Author

validate fields without extending ActonSupport

Fabiano Souza
Greenhorn

Joined: Sep 26, 2008
Posts: 11
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

Joined: Oct 29, 2001
Posts: 8971
    
    9

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.


[How To Ask Questions On JavaRanch]
Fabiano Souza
Greenhorn

Joined: Sep 26, 2008
Posts: 11
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

Joined: Oct 29, 2001
Posts: 8971
    
    9

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

Joined: Sep 26, 2008
Posts: 11
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

Joined: Oct 29, 2001
Posts: 8971
    
    9

If by "nested" you mean subclass and superclass, it could work, but the subclass would have to specifically invoke super.validate().
Fabiano Souza
Greenhorn

Joined: Sep 26, 2008
Posts: 11
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..
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: validate fields without extending ActonSupport