Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Return types from execute() method in struts2 action

 
Souvvik Basu
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.
 
Mohana Rao Sv
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?
 
Jesus Mireles
Ranch Hand
Posts: 122
IntelliJ IDE Java Mac
  • 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 ...
 
shailesh thakur
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.
 
jatan bhavsar
Ranch Hand
Posts: 299
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic