• 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
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Return types from execute() method in struts2 action

 
Ranch Hand
Posts: 96
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have been trying to learn Struts 2 through materials available on the net. One thing I just picked up is that there are 5 different return values from the action's execute() method, that are pre-defined in the framework, namely SUCCESS, ERROR, INPUT, LOGIN, NONE.
What I have a doubt about is...we can always set our own return value in the struts.xml file, in the action element. I can obviously do something like the following

and then make the execute() method return "reallycoolresult".

Can't I?
If I can't, then please tell me where my understanding went wrong. If I can, then what's the point of having pre-defined return values?

Please help me clear this confusion.
 
Ranch Hand
Posts: 485
Eclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, you can do that.
 
Souvvik Basu
Ranch Hand
Posts: 96
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I can, then what's the point/advantage of having pre-defined return types?
 
Ranch Hand
Posts: 122
Mac IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm sure those are predefined because the majority of people use things like success, error, input, none, login.

The fact that you can return any other doesnt matter, the point is the method still returns a string ... you map that string to some result name ...
 
Greenhorn
Posts: 15
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I tried returning custom values from my execute method, but it was always returning error and the custom value was ignored.The page corresponding to "error" return value was called.
 
Mohana Rao Sv
Ranch Hand
Posts: 485
Eclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Above Cause your method returning error somewhere you are getting exception fix the problem.
 
Ranch Hand
Posts: 300
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I tried returning custom values from my execute method, but it was always returning error and the custom value was ignored




What you mean by custome value?? Please post some code and stack trace so we can have better idea about the problem.

Regards
jatan
 
Oh the stink of it! Smell my tiny ad!
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic