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

java.lang.Object
  extended by org.apache.struts.action.Action
      extended by jp.terasoluna.fw.web.struts.actions.ActionEx
          extended by jp.terasoluna.fw.web.struts.actions.DispatchAction

public class DispatchAction
extends ActionEx

Performs distribution of forward destination of action.

Decides the forward path by using the request paramater.
Please note that the specifications differ from the DispatchAction and LookupDispatchAction provided by Struts.

Perform the settings of request parameter key in Bean definition file as and when needed. (Default value is "event").

In the following definition file, request parameter key is set to custom-event.

Configuration of Bean definition file

  <bean name="/dispatch" scope="prototype"
    class="jp.terasoluna.fw.web.struts.actions.DispatchAction">
    <property name="event">
      <value>custom-event</value>
    </property>
  </bean>
  

Forward name is decided. The priority sequence is as follows:

  1. Request parameter key value from which the "forward_" prefix is removed.
  2. Request parameter key from which "forward_" prefix is removed.
  3. Fixed "default" (When the invalid forward path such as event="XXXX","forward_XXXX" is specified)
When the forward name is "#input", input attribute of struts-config.xml becomes the forward path.
When the forward name is not "#input", forward path is decided as per the contents specified in the forward element of struts-config.xml.

Configuration of struts-config.xml

  <action path="/dispatch"
    name="_sampleForm"
    scope="session"
    input="/prev.jsp">
    <forward name="regist" path="/userRegist.do"/>
    <forward name="search" path="/userSearch.do"/>
    <forward name="update" path="/userUpdate.do"/>
    <forward name="decide" path="/prev.do"/>
    <forward name="default" path="/prev.do"/>
  </action>
 

Description example of JSP

  ...
  <html:radio property="custom-event" value="forward_regist"/>
  <html:radio property="custom-event" value="forward_search"/>
  <html:radio property="custom-event" value="forward_update"/>
  <html:radio property="custom-event" value="forward_#input"/>
  <html:submit property="forward_decide" value="Decide"/>
  <html:submit value="Back"/>
  ...
  
Define "forward_" + logical forward name as the request parameter value.

The forward path for the respective operation is as follows.

  1. When the first radio button is selected and "decide" is clicked, forward name becomes "regist" and forward path becomes "/userRegist.do"
  2. When the fourth button is selected and "decide" is clicked, forward name becomes "#input" and forward path becomes "/prev.do"
  3. If "decide" is clicked without selecting the radio button, forward name becomes "decide" and forward path becomes "/prev.do"
  4. When the "Back" is clicked, forward name becomes "default" and forward path becomes "/prev.do"


Field Summary
private  java.lang.String event
          Poperty name that indicates foward path.
private static java.lang.String FORWARD_DEFAULT
          Logical forward name of default forward path when there was no forward indicator in the request parameter.
private static java.lang.String FORWARD_PREFIX
          Prefix of request parameter key for identifying the forward indicator.
private static org.apache.commons.logging.Log log
          Log class.
 
Fields inherited from class jp.terasoluna.fw.web.struts.actions.ActionEx
FORWARD_TXTOKEN_ERROR
 
Fields inherited from class org.apache.struts.action.Action
defaultLocale, servlet
 
Constructor Summary
DispatchAction()
           
 
Method Summary
protected  org.apache.struts.action.ActionForward cancelled(org.apache.struts.action.ActionMapping mapping, org.apache.struts.action.ActionForm form, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
          Decides the forward path when cancellation flag is set in the request. At the time cancelling action forward, since ActionForward is returned as null, the forward path should be implemented by overriding the method in the sub class of this class.
protected  java.lang.String doDetermineForward(java.util.Map params, java.lang.String event)
          Dispatch the forward action based on the request parameter. When the params is null, returns default string.
 org.apache.struts.action.ActionForward doExecute(org.apache.struts.action.ActionMapping mapping, org.apache.struts.action.ActionForm form, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res)
          Performs the distribution of forward path.
protected  boolean exists(java.util.Map params, java.lang.String name)
          Check if the parameter with the specified name exists in the request parameter.
 void setEvent(java.lang.String value)
          Sets the property name that indicates forward path.
 
Methods inherited from class jp.terasoluna.fw.web.struts.actions.ActionEx
addErrors, addMessages, execute, isSaveToken, isTokenCheck, processTokenCheck, setSaveToken, setTokenCheck
 
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_DEFAULT

private static final java.lang.String FORWARD_DEFAULT
Logical forward name of default forward path when there was no forward indicator in the request parameter.

See Also:
Constant Field Values

FORWARD_PREFIX

private static final java.lang.String FORWARD_PREFIX
Prefix of request parameter key for identifying the forward indicator.

See Also:
Constant Field Values

event

private java.lang.String event
Property name that indicates forward path.

Constructor Detail

DispatchAction

public DispatchAction()
Method Detail

setEvent

public void setEvent(java.lang.String value)
Sets the property name which indicates forward path.

Parameters:
value - Forward path property name

doExecute

public org.apache.struts.action.ActionForward doExecute(org.apache.struts.action.ActionMapping mapping,
                                                        org.apache.struts.action.ActionForm form,
                                                        javax.servlet.http.HttpServletRequest req,
                                                        javax.servlet.http.HttpServletResponse res)
Performs forward process of the action.

Once the action is forwarded, it deletes server blockage flag.
The actual forward path is decided by doDetamineForward().

Specified by:
doExecute in class ActionEx
Parameters:
mapping - Action mapping
form - Action form
req - HTTPRequest
res - HTTPResponse
Returns:
Forward path information

doDetermineForward

protected java.lang.String doDetermineForward(java.util.Map params,
                                              java.lang.String event)
Dispatch the forward action based on the request parameter. When params is null, it returns default string.

Parameters:
params - Request parameter(Map format)
event - Event name specified in action mapping
Returns:
Logical forward name of forward action

exists

protected boolean exists(java.util.Map params,
                         java.lang.String name)
Check if the parameter with the specified name, exists in the request parameter.

Parameters:
params - Request parameter(MAp format)
name - Request parameter name
Returns:
IF the request parameter name exists, true

cancelled

protected org.apache.struts.action.ActionForward cancelled(org.apache.struts.action.ActionMapping mapping,
                                                           org.apache.struts.action.ActionForm form,
                                                           javax.servlet.http.HttpServletRequest request,
                                                           javax.servlet.http.HttpServletResponse response)
Decides the forward path when the cancellation flag is set in the request. At the time cancelling action forward, since ActionForward is returned as null, the forward path should be implemented by overriding the method in the sub class of this class.

Parameters:
mapping - Action mapping
form - Action form
request - HTTP request
response - HTTP response
Returns:
Action forward