org.beyondcode.struts.dispatcher
Class FormDispatcherAction
java.lang.Object
|
+--org.apache.struts.action.Action
|
+--org.beyondcode.struts.dispatcher.FormDispatcherAction
- public class FormDispatcherAction
- extends org.apache.struts.action.Action
This class forwards an incoming request to another Action,
when it finds a request parameter with the same name as one the local
forwards.
In Struts, an HTML form is always submitted to a single action.
In case the HTML form has several submit button, this class can be
used to select which one has been clicked and forward the request to
a different action accordingly.
Example:
JSP:
...
<html:form action="/formHandler">
...
<html:submit property="delete" value="Delete Selected" />
<html:submit property="save" value="Save Selected" />
</html:form>
...
struts-config.xml:
...
<action path="/formHandler" type="org.beyondcode.struts.dispatcher.FormDispatcherAction">
<forward name="delete" path="/demo/delete" redirect="false" />
<forward name="save" path="/demo/save" redirect="false" />
</action>
<action path="/delete" type="HomeAction" >
<set-property property="method" value="doDelete" />
<forward name="success" path="/WEB-INF/jsp/page.jsp" redirect="false" />
</action>
<action path="/save" type="HomeAction" >
<set-property property="method" value="doSave" />
<forward name="success" path="/WEB-INF/jsp/page.jsp" redirect="false" />
</action>
...
This class does not need to be extended for custom applications!
- Author:
- Philipp K. Janert
|
Field Summary |
protected static org.apache.struts.util.MessageResources |
messages
Handle to properties file with error messages. |
| Fields inherited from class org.apache.struts.action.Action |
DATA_SOURCE_KEY, defaultLocale, ERROR_KEY, EXCEPTION_KEY, FORM_BEANS_KEY, FORWARDS_KEY, LOCALE_KEY, MAPPING_KEY, MAPPINGS_KEY, MESSAGES_KEY, MULTIPART_KEY, servlet, SERVLET_KEY, TRANSACTION_TOKEN_KEY |
|
Method Summary |
org.apache.struts.action.ActionForward |
perform(org.apache.struts.action.ActionMapping mapping,
org.apache.struts.action.ActionForm form,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
This method compares the names of the request parameters and
the names of the ActionForwards (as defined in the
mapping). |
| Methods inherited from class org.apache.struts.action.Action |
generateToken, getLocale, getResources, getServlet, isCancelled, isTokenValid, perform, perform, perform, resetToken, saveErrors, saveToken, setLocale, setServlet, toHex |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
messages
protected static org.apache.struts.util.MessageResources messages
- Handle to properties file with error messages.
FormDispatcherAction
public FormDispatcherAction()
perform
public org.apache.struts.action.ActionForward perform(org.apache.struts.action.ActionMapping mapping,
org.apache.struts.action.ActionForm form,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
- This method compares the names of the request parameters and
the names of the
ActionForwards (as defined in the
mapping). When it finds a request parameter with
the same name as one of the forwards, it transfers control to
the Action given by the Path property
of the respective forward. The transfer is done as a local
dispatch (not through client redirection). If no match
is found, null is returned. If several matches
exist, one is chosen arbitrarily.
- Overrides:
perform in class org.apache.struts.action.Action
- Parameters:
mapping - form - request - response -
- Returns:
- Selected forward, or
null if none found.