|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.struts.action.Action
public class Action
An Action is an adapter between the contents of an
incoming HTTP request and the corresponding business logic that should be
executed to process this request. The controller (RequestProcessor) will
select an appropriate Action for each request, create an instance (if
necessary), and call the execute
method.
Actions must be programmed in a thread-safe manner, because the controller will share the same instance for multiple simultaneous requests. This means you should design with the following items in mind:
When an Action
instance is first created, the controller
will call setServlet
with a non-null argument to identify the
servlet instance to which this Action is attached. When the servlet is to
be shut down (or restarted), the setServlet
method will be
called with a null
argument, which can be used to clean up any
allocated resources in use by this Action.
Field Summary | |
---|---|
protected ActionServlet |
servlet
The servlet to which we are attached. |
Constructor Summary | |
---|---|
Action()
|
Method Summary | |
---|---|
protected void |
addErrors(HttpServletRequest request,
ActionMessages errors)
Adds the specified errors keys into the appropriate request attribute for use by the <html:errors> tag, if any messages are required. |
protected void |
addMessages(HttpServletRequest request,
ActionMessages messages)
Adds the specified messages keys into the appropriate request attribute for use by the <html:messages> tag (if messages="true" is set), if any messages are required. |
ActionForward |
execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
Process the specified HTTP request, and create the corresponding HTTP response (or forward to another web component that will create it), with provision for handling exceptions thrown by the business logic. |
ActionForward |
execute(ActionMapping mapping,
ActionForm form,
ServletRequest request,
ServletResponse response)
Process the specified non-HTTP request, and create the corresponding non-HTTP response (or forward to another web component that will create it), with provision for handling exceptions thrown by the business logic. |
protected String |
generateToken(HttpServletRequest request)
Generate a new transaction token, to be used for enforcing a single request for a particular transaction. |
protected ActionMessages |
getErrors(HttpServletRequest request)
Retrieves any existing errors placed in the request by previous actions. |
protected Locale |
getLocale(HttpServletRequest request)
Return the user's currently selected Locale. |
protected ActionMessages |
getMessages(HttpServletRequest request)
Retrieves any existing messages placed in the request by previous actions. |
protected MessageResources |
getResources(HttpServletRequest request)
Return the default message resources for the current module. |
protected MessageResources |
getResources(HttpServletRequest request,
String key)
Return the specified message resources for the current module. |
ActionServlet |
getServlet()
Return the servlet instance to which we are attached. |
protected boolean |
isCancelled(HttpServletRequest request)
Returns true if the current form's cancel button was
pressed. |
protected boolean |
isTokenValid(HttpServletRequest request)
Return true if there is a transaction token stored in
the user's current session, and the value submitted as a request
parameter with this action matches it. |
protected boolean |
isTokenValid(HttpServletRequest request,
boolean reset)
Return true if there is a transaction token stored in
the user's current session, and the value submitted as a request
parameter with this action matches it. |
protected void |
resetToken(HttpServletRequest request)
Reset the saved transaction token in the user's session. |
protected void |
saveErrors(HttpServletRequest request,
ActionMessages errors)
Save the specified error messages keys into the appropriate request attribute for use by the <html:errors> tag, if any messages are required. |
protected void |
saveErrors(HttpSession session,
ActionMessages errors)
Save the specified error messages keys into the appropriate session attribute for use by the <html:messages> tag (if messages="false") or <html:errors>, if any error messages are required. |
protected void |
saveMessages(HttpServletRequest request,
ActionMessages messages)
Save the specified messages keys into the appropriate request attribute for use by the <html:messages> tag (if messages="true" is set), if any messages are required. |
protected void |
saveMessages(HttpSession session,
ActionMessages messages)
Save the specified messages keys into the appropriate session attribute for use by the <html:messages> tag (if messages="true" is set), if any messages are required. |
protected void |
saveToken(HttpServletRequest request)
Save a new transaction token in the user's current session, creating a new session if necessary. |
protected void |
setLocale(HttpServletRequest request,
Locale locale)
Set the user's currently selected Locale into their
HttpSession . |
void |
setServlet(ActionServlet servlet)
Set the servlet instance to which we are attached (if servlet is non-null), or release any allocated resources
(if servlet is null). |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected transient ActionServlet servlet
The servlet to which we are attached.
Constructor Detail |
---|
public Action()
Method Detail |
---|
public ActionServlet getServlet()
Return the servlet instance to which we are attached.
public void setServlet(ActionServlet servlet)
Set the servlet instance to which we are attached (if
servlet
is non-null), or release any allocated resources
(if servlet
is null).
servlet
- The new controller servlet, if anypublic ActionForward execute(ActionMapping mapping, ActionForm form, ServletRequest request, ServletResponse response) throws Exception
Process the specified non-HTTP request, and create the corresponding
non-HTTP response (or forward to another web component that will create
it), with provision for handling exceptions thrown by the business
logic. Return an ActionForward
instance describing where and
how control should be forwarded, or null
if the response
has already been completed.
The default implementation attempts to forward to the HTTP version of this method.
mapping
- The ActionMapping used to select this instanceform
- The optional ActionForm bean for this request (if any)request
- The non-HTTP request we are processingresponse
- The non-HTTP response we are creating
null
if the response has been completed.
Exception
- if the application business logic throws an
exception.public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception
Process the specified HTTP request, and create the corresponding
HTTP response (or forward to another web component that will create
it), with provision for handling exceptions thrown by the business
logic. Return an ActionForward
instance describing where and
how control should be forwarded, or null
if the response
has already been completed.
mapping
- The ActionMapping used to select this instanceform
- The optional ActionForm bean for this request (if any)request
- The HTTP request we are processingresponse
- The HTTP response we are creating
null
if the response has been completed.
Exception
- if the application business logic throws an
exceptionprotected void addMessages(HttpServletRequest request, ActionMessages messages)
request
- The servlet request we are processingmessages
- Messages objectprotected void addErrors(HttpServletRequest request, ActionMessages errors)
request
- The servlet request we are processingerrors
- Errors objectprotected String generateToken(HttpServletRequest request)
Generate a new transaction token, to be used for enforcing a single request for a particular transaction.
request
- The request we are processing
protected ActionMessages getErrors(HttpServletRequest request)
new
ActionMessages()
at the beginning of an Action
.
This will prevent saveErrors() from wiping out any existing Errors
request
- The servlet request we are processing
protected Locale getLocale(HttpServletRequest request)
Return the user's currently selected Locale.
request
- The request we are processing
protected ActionMessages getMessages(HttpServletRequest request)
Retrieves any existing messages placed in the request by previous
actions. This method could be called instead of creating a new
ActionMessages()
at the beginning of an Action
This
will prevent saveMessages() from wiping out any existing Messages
request
- The servlet request we are processing
protected MessageResources getResources(HttpServletRequest request)
Return the default message resources for the current module.
request
- The servlet request we are processing
protected MessageResources getResources(HttpServletRequest request, String key)
Return the specified message resources for the current module.
request
- The servlet request we are processingkey
- The key specified in the message-resources element for
the requested bundle.
protected boolean isCancelled(HttpServletRequest request)
Returns true
if the current form's cancel button was
pressed. This method will check if the Globals.CANCEL_KEY
request attribute has been set, which normally occurs if the cancel
button generated by CancelTag was pressed by the user
in the current request. If true
, validation performed by
an ActionForm's validate()
method will
have been skipped by the controller servlet.
Since Action 1.3.0, the mapping for a cancellable Action must also have the new "cancellable" property set to true. If "cancellable" is not set, and the magic Cancel token is found in the request, the standard Composable Request Processor will throw an InvalidCancelException.
request
- The servlet request we are processing
true
if the cancel button was pressed;
false
otherwise.protected boolean isTokenValid(HttpServletRequest request)
Return true
if there is a transaction token stored in
the user's current session, and the value submitted as a request
parameter with this action matches it. Returns false
under
any of the following circumstances:
request
- The servlet request we are processing
true
if there is a transaction token and it is
valid; false
otherwise.protected boolean isTokenValid(HttpServletRequest request, boolean reset)
Return true
if there is a transaction token stored in
the user's current session, and the value submitted as a request
parameter with this action matches it. Returns false
under
any of the following circumstances:
request
- The servlet request we are processingreset
- Should we reset the token after checking it?
true
if there is a transaction token and it is
valid; false
otherwise.protected void resetToken(HttpServletRequest request)
Reset the saved transaction token in the user's session. This indicates that transactional token checking will not be needed on the next request that is submitted.
request
- The servlet request we are processingprotected void saveErrors(HttpServletRequest request, ActionMessages errors)
Save the specified error messages keys into the appropriate request attribute for use by the <html:errors> tag, if any messages are required. Otherwise, ensure that the request attribute is not created.
request
- The servlet request we are processingerrors
- Error messages objectprotected void saveMessages(HttpServletRequest request, ActionMessages messages)
Save the specified messages keys into the appropriate request attribute for use by the <html:messages> tag (if messages="true" is set), if any messages are required. Otherwise, ensure that the request attribute is not created.
request
- The servlet request we are processing.messages
- The messages to save. null
or empty
messages removes any existing ActionMessages in the
request.protected void saveMessages(HttpSession session, ActionMessages messages)
Save the specified messages keys into the appropriate session attribute for use by the <html:messages> tag (if messages="true" is set), if any messages are required. Otherwise, ensure that the session attribute is not created.
session
- The session to save the messages in.messages
- The messages to save. null
or empty
messages removes any existing ActionMessages in the
session.protected void saveErrors(HttpSession session, ActionMessages errors)
Save the specified error messages keys into the appropriate session attribute for use by the <html:messages> tag (if messages="false") or <html:errors>, if any error messages are required. Otherwise, ensure that the session attribute is empty.
session
- The session to save the error messages in.errors
- The error messages to save. null
or empty
messages removes any existing error ActionMessages in
the session.protected void saveToken(HttpServletRequest request)
Save a new transaction token in the user's current session, creating a new session if necessary.
request
- The servlet request we are processingprotected void setLocale(HttpServletRequest request, Locale locale)
Set the user's currently selected Locale
into their
HttpSession
.
request
- The request we are processinglocale
- The user's selected Locale to be set, or null to select
the server's default Locale
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |