jp.terasoluna.fw.web.struts.actions
Class ActionEx

java.lang.Object
  extended by org.apache.struts.action.Action
      extended by jp.terasoluna.fw.web.struts.actions.ActionEx
Direct Known Subclasses:
AbstractBLogicAction, ClearSessionAction, DispatchAction, ForwardAction, LogoffAction, MakeSessionDirectoryAction, ReloadCodeListAction

public abstract class ActionEx
extends org.apache.struts.action.Action

Action class.

Log output function and transaction token check function are added in the Action of Struts.
To use these functions, inherit this class.
To use this class, create the subclass that overrides doExecute() method and set the class name in the type parameter of <action> element in struts-config.xml.
Transaction token check is the function which prevents the duplication of submit. Duplicate submit is performed by pressing the submit button twice or using "Back" button of the browser.
Following settings are required to perform transaction token check.

when the ActionEx is used, token is automatically stored through saveToken(). Following settings are required when the token is not to be stored.
Following is the configuration example of Bean definition file and struts-config.xml which includes transaction token check functionality.

Configuration example of Bean definition file in subclass LogoffAction

  <bean name="/admin/Logout" scope="prototype"
      class="jp.terasoluna.fw.web.struts.actions.LogoffAction">
    <property property="tokenCheck">
      <value>true</value>
    </property>
    <property property="saveToken">
      <value>false</value>
    </property>
  </bean>
  

Configuration example of struts-config.xml in subclass LogoffAction

  <action path="/admin/Logout"
      name="logonSampleForm"
      scope="session"
      parameter="/sub/logout.jsp">
    <forward name="txtoken-error" modeule="/sub"
        path="/doubleRegistError.jsp"/>
  </action>
  
When the module is set in the "forward" element by appending the "/" slash at the beginning of the path, it is possible to make the modulewise transition by using the relative path.
At the time of inheriting this function in the subclass, doExecute() method needs to be implemented as the entry point.
For the settings of action mapping, refer to ActionMappingEx.

See Also:
ActionMappingEx

Field Summary
protected static java.lang.String FORWARD_TXTOKEN_ERROR
          Logcial forward name when there is trasaction token check error.
private static org.apache.commons.logging.Log log
          Log class.
private  boolean saveToken
          Check whether the transaction token is to be stored. Default is true(store).
private  boolean tokenCheck
          Check whether to perform the transaction token check. Default is false(Do not check).
 
Fields inherited from class org.apache.struts.action.Action
defaultLocale, servlet
 
Constructor Summary
ActionEx()
           
 
Method Summary
protected  void addErrors(javax.servlet.http.HttpSession session, org.apache.struts.action.ActionMessages errors)
          Fetches ActionMessages from the session by using Globals.ERROR_KEY, adds the ActionMessages and stores it again.
protected  void addMessages(javax.servlet.http.HttpSession session, org.apache.struts.action.ActionMessages messages)
          Fetches the ActionMessages from the session by using Globals.MESSAGE_KEY, adds the ActionMessages and stores it again.
abstract  org.apache.struts.action.ActionForward doExecute(org.apache.struts.action.ActionMapping mapping, org.apache.struts.action.ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Abstract method that executes the action.
 org.apache.struts.action.ActionForward execute(org.apache.struts.action.ActionMapping mapping, org.apache.struts.action.ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Executes the action.
protected  boolean isSaveToken()
          Fetches the flag that stores transaction token.
protected  boolean isTokenCheck()
          Fetches the flag that checks transaction token.
protected  boolean processTokenCheck(org.apache.struts.action.ActionMapping mapping, javax.servlet.http.HttpServletRequest req)
          Checks the transaction token.
 void setSaveToken(boolean saveToken)
          Sets the flag which stores the transaction token.
 void setTokenCheck(boolean tokenCheck)
          Sets the flag that checks transaction token.
 
Methods inherited from class org.apache.struts.action.Action
addErrors, addMessages, execute, generateToken, getDataSource, getDataSource, getErrors, getLocale, getMessages, getResources, getResources, getServlet, isCancelled, isTokenValid, isTokenValid, resetToken, saveErrors, saveErrors, saveErrors, saveMessages, saveMessages, saveToken, setLocale, setServlet
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static org.apache.commons.logging.Log log
Log class.


FORWARD_TXTOKEN_ERROR

protected static final java.lang.String FORWARD_TXTOKEN_ERROR
Logical forward name when there is a transaction token check error.

See Also:
Constant Field Values

tokenCheck

private boolean tokenCheck
Check whether to perform transaction token check. Default is false(not to be performed).


saveToken

private boolean saveToken
Check whether to store the transaction token. Default is true(store).

Constructor Detail

ActionEx

public ActionEx()
Method Detail

setTokenCheck

public void setTokenCheck(boolean tokenCheck)
Sets the flag that checks transaction token.

Parameters:
tokenCheck - Transaction token check flag

setSaveToken

public void setSaveToken(boolean saveToken)
Sets the flag that stores transaction token.

Parameters:
saveToken - Transaction token storage flag

isTokenCheck

protected boolean isTokenCheck()
Fetches the flag that checks transaction token.

Returns:
Transaction token check flag

isSaveToken

protected boolean isSaveToken()
Fetches the flag that stores transaction token

Returns:
Transaction token storage flag

execute

public org.apache.struts.action.ActionForward execute(org.apache.struts.action.ActionMapping mapping,
                                                      org.apache.struts.action.ActionForm form,
                                                      javax.servlet.http.HttpServletRequest request,
                                                      javax.servlet.http.HttpServletResponse response)
                                               throws java.lang.Exception
Executes the action.

Before calling doExecute() method implemented in subclass, update the "modified" attribute of action form with "false".
After performing doExecute(), store the SKIP_POPULATE in the "request" attribute if there is a change in the field value of action form. processPopulate() is controlled by the RequestProcessorEx.

Overrides:
execute in class org.apache.struts.action.Action
Parameters:
mapping - Action mapping linked with this action
form - Action form
request - Request information
response - Response information
Returns:
Transition information
Throws:
java.lang.Exception - Exception at the time of executing action

doExecute

public abstract org.apache.struts.action.ActionForward doExecute(org.apache.struts.action.ActionMapping mapping,
                                                                 org.apache.struts.action.ActionForm form,
                                                                 javax.servlet.http.HttpServletRequest request,
                                                                 javax.servlet.http.HttpServletResponse response)
                                                          throws java.lang.Exception
Abstarct method that executes the action.

Override this method in subclass and extend the functions of action.

Parameters:
mapping - Action mapping linked with this action
form - Action form
request - Request information
response - Response information
Returns:
Transition information
Throws:
java.lang.Exception - Unexpected exception

processTokenCheck

protected boolean processTokenCheck(org.apache.struts.action.ActionMapping mapping,
                                    javax.servlet.http.HttpServletRequest req)
Checks the transaction token.

Parameters:
mapping - Action mapping
req - HTTP rquest
Returns:
true when the token is valid

addErrors

protected void addErrors(javax.servlet.http.HttpSession session,
                         org.apache.struts.action.ActionMessages errors)
Fetches ActionMessages from the session by using Globals.ERROR_KEY, adds the ActionMessages and stores it again.

Parameters:
session - Session
errors - Error message information

addMessages

protected void addMessages(javax.servlet.http.HttpSession session,
                           org.apache.struts.action.ActionMessages messages)
Fetches ActionMessages from the session by using Globals.MESSAGE_KEY, adds ActionMessages and stores it again.

Parameters:
session - Session
messages - Message information