wood burning stoves 2.0*
The moose likes Struts and the fly likes Return types from execute() method in struts2 action Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Return types from execute() method in struts2 action" Watch "Return types from execute() method in struts2 action" New topic
Author

Return types from execute() method in struts2 action

Souvvik Basu
Ranch Hand

Joined: Apr 05, 2010
Posts: 96
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

Joined: Aug 01, 2007
Posts: 485

yes, you can do that.


ocjp 6 — Feeding a person with food is a great thing in this world. Feeding the same person by transferring the knowledge is far more better thing. The reason is the amount of satisfaction which we get through food is of only one minute or two. But the satisfaction which we can get through the knowledge is of life long.
Souvvik Basu
Ranch Hand

Joined: Apr 05, 2010
Posts: 96
If I can, then what's the point/advantage of having pre-defined return types?
Jesus Mireles
Ranch Hand

Joined: Mar 10, 2010
Posts: 122

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

Joined: May 30, 2012
Posts: 15

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.


Regards,
Shailesh
OCJP 1.6 , OCWCD 1.5
Mohana Rao Sv
Ranch Hand

Joined: Aug 01, 2007
Posts: 485

@Above Cause your method returning error somewhere you are getting exception fix the problem.
jatan bhavsar
Ranch Hand

Joined: Jul 23, 2008
Posts: 296

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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Return types from execute() method in struts2 action