Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts2 whats the need for extending ActionSupport class

 
PavanPL KalyanK
Ranch Hand
Posts: 212
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 9510
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
PavanPL KalyanK
Ranch Hand
Posts: 212
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9510
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 212
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9510
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 212
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ankit and David for your great explanation
 
Mare Eswaran
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thats really a useful reply..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic