Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Struts2 whats the need for extending ActionSupport class

 
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 ?
 
Sheriff
Posts: 9674
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • 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: 9674
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • 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: 9674
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • 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...
 
Author
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
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thats really a useful reply..
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic