Sunday, March 1, 2009

Return Type String Constants In Action Interface

This blog post intends to answer the following questions :-
  1. What are the String constants defined in the Action interface?
  2. What are the different String constants in the Action interface used for?
  3. What is the use of the following- SUCCESS, INPUT, ERROR, LOGIN, NONE?
The Action interface defines fines String constants that can be used as return types from any function in a Struts 2 Class. Since we use the execute method in most Struts 2 applications as our method where all the so called action takes place, these string constants are mostly used as return values in this function.

All the five string constants have a different purpose to solve in the Struts 2 framework.
  1. SUCCESS :- This return type is used to indicate that the result of the operation has been successful and the application is eligible to flow as in normal operating conditions.
  2. INPUT :- This return type is used to indicate that the requested action cannot be completed due to inappropriate or insufficient data entered by the user.
  3. ERROR :- This return type is used to indicate that a certain error condition was produced while performing the requested operation.
  4. LOGIN :- This return type is used to indicate that the action need proper authentication before it can perform the operation.
  5. NONE :- This return type indicates that the completion of the action is not associated with the display of a view component to the user.
You can also return your own strings form your action classes instead of the above mentioned ones. But then be sure to map your custom return value to a view in the struts.xml file using the result element as follows.

<result name="my_own_string">/myview.jsp</result>

Happy Programming ;)

Signing Off
Ryan

No comments: