aspose file tools*
The moose likes Struts and the fly likes Struts2 whats the need for extending ActionSupport class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts2 whats the need for extending ActionSupport class " Watch "Struts2 whats the need for extending ActionSupport class " New topic
Author

Struts2 whats the need for extending ActionSupport class

PavanPL KalyanK
Ranch Hand

Joined: Feb 28, 2009
Posts: 212

Could anybody please tell why our Action classshould extend ActionSupport .

The only advanatgae i could see is that we can get access to the predefined constants . Is this the only advantage ?
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

Well you also get a default execute method which returns success, so you can create empty actions if there is no business logic. It also implements a lot of interfaces like TextProvider for your convenience. Look at the ActionSupport documentation...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
PavanPL KalyanK
Ranch Hand

Joined: Feb 28, 2009
Posts: 212
Thanks Ankit ,

I saw its importance in validate() .



But its return type is void , how this is working . Can you please tell me .
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

Well there is a Map of validation errors in the ActionSupport class. So when you call the addFieldError method, your field name is added as the key to a new entry in the map and the message is added as a value to the new entry. It goes like this



The original code might not look exactly like this in ActionSupport class but this is just the concept...
PavanPL KalyanK
Ranch Hand

Joined: Feb 28, 2009
Posts: 212
Thanks Ankit .

But i was an expecting a answer in terms of workflowinterceptor which automatically does the work . If you know this can you please give an idea on this .
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

Well I couldn't understand your question properly, but the workflow interceptor calls the ActionSupport.hasFieldErrors() to check if there were any errors during call to validate method and if that method returns true, then workflow interceptor stops the execution of the request and returns the input page configured for that action to the user...
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

All of the validation and I18N is implemented by ActionSupport; if you don't extend it, and you want validation and I18N to work, you must implement it all yourself, which seems like a lot of work for something that's already provided.
PavanPL KalyanK
Ranch Hand

Joined: Feb 28, 2009
Posts: 212
Thanks Ankit and David for your great explanation
Mare Eswaran
Greenhorn

Joined: Feb 10, 2012
Posts: 2
Thats really a useful reply..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts2 whats the need for extending ActionSupport class