craigmcc 2002/07/05 15:09:21
Modified: src/example/org/apache/struts/webapp/example
LogonAction.java
src/share/org/apache/struts/action ActionMapping.java
RequestProcessor.java
web/example/WEB-INF struts-config.xml
Log:
Support the new "inputForward" boolean property on ControllerConfig that
(if set to true) defines the "input" attribute of an <action> element to
be the name of a local or global forward that is used to calculate the
ultimate URL to which control is returned on validation errors. The default
behavior (false) assumes that the "input" attribute is a subapp-relative
URL (backwards compatible with the previous behavior).
ActionMapping - Add a new getInputForward() method that will return an
ActionForward corresponding to the input form, no matter whether or not
the "inputForward" property is set. This is useful in Actions that want
to create "validation error" messages and return to the input form
themselves, such as LogonAction in the struts-example webapp.
struts-config.xml - The struts-example webapp now sets the "inputForward"
property to true, and utilizes the new features.
Revision Changes Path
1.10 +5 -5
jakarta-struts/src/example/org/apache/struts/webapp/example/LogonAction.java
Index: LogonAction.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/src/example/org/apache/struts/webapp/example/LogonAction.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- LogonAction.java 23 Jun 2002 04:59:33 -0000 1.9
+++ LogonAction.java 5 Jul 2002 22:09:20 -0000 1.10
@@ -151,7 +151,7 @@
// Report any errors we have discovered back to the original form
if (!errors.empty()) {
saveErrors(request, errors);
- return (new ActionForward(mapping.getInput()));
+ return (mapping.getInputForward());
}
// Save our logged-in user in the session
1.25 +21 -4
jakarta-struts/src/share/org/apache/struts/action/ActionMapping.java
Index: ActionMapping.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/src/share/org/apache/struts/action/ActionMapping.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- ActionMapping.java 24 Jun 2002 18:53:01 -0000 1.24
+++ ActionMapping.java 5 Jul 2002 22:09:21 -0000 1.25
@@ -170,4 +170,21 @@
}
+ /**
+ * <p>Create (if necessary) and return an {@link ActionForward} that
+ * corresponds to the <code>input</code> property of this Action.
+ *
+ * @since Struts 1.1b2
+ */
+ public ActionForward getInputForward() {
+
+ if (getApplicationConfig().getControllerConfig().getInputForward()) {
+ return (findForward(getInput()));
+ } else {
+ return (new ActionForward(getInput()));
+ }
+
+ }
+
+
}
1.13 +18 -21
jakarta-struts/src/share/org/apache/struts/action/RequestProcessor.java
Index: RequestProcessor.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/src/share/org/apache/struts/action/RequestProcessor.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- RequestProcessor.java 30 Jun 2002 03:38:29 -0000 1.12
+++ RequestProcessor.java 5 Jul 2002 22:09:21 -0000 1.13
@@ -80,6 +80,7 @@
import org.apache.struts.config.ControllerConfig;
import org.apache.struts.config.ExceptionConfig;
import org.apache.struts.config.FormBeanConfig;
+import org.apache.struts.config.ForwardConfig;
import org.apache.struts.upload.MultipartRequestWrapper;
import org.apache.struts.taglib.html.Constants;
import org.apache.struts.util.MessageResources;
@@ -396,22 +397,12 @@
request = ((MultipartRequestWrapper) request).getRequest();
}
- String path = forward.getPath();
+ String uri = RequestUtils.forwardURL(request, forward);
if (forward.getRedirect()) {
- if (path.startsWith("/")) {
- if (forward.getContextRelative()) {
- path = request.getContextPath() + path;
- } else {
- path = request.getContextPath() +
- appConfig.getPrefix() + path;
- }
- }
- response.sendRedirect(response.encodeRedirectURL(path));
+ response.sendRedirect
+ (response.encodeRedirectURL(request.getContextPath() + uri));
} else {
- if (path.startsWith("/") && !forward.getContextRelative()) {
- path = appConfig.getPrefix() + path;
- }
- doForward( path, request, response);
+ doForward(uri, request, response);
}
}
@@ -949,7 +940,13 @@
if (request instanceof MultipartRequestWrapper) {
request = ((MultipartRequestWrapper) request).getRequest();
}
- String uri = appConfig.getPrefix() + input;
+ String uri = null;
+ if (appConfig.getControllerConfig().getInputForward()) {
+ ForwardConfig forward = mapping.findForward(input);
+ uri = RequestUtils.forwardURL(request, forward);
+ } else {
+ uri = appConfig.getPrefix() + input;
+ }
doForward(uri, request, response);
return (false);
@@ -958,7 +955,7 @@
/**
* Do a forward to specified uri using request dispatcher.
* This method is used by all internal method needi
- * @param uri Uri or Definition name to forward
+ * @param uri Context-relative URI to forward to
* @param request Current page request
* @param response Current page response
* @since Struts 1.1
@@ -982,7 +979,7 @@
/**
* Do an include of specified uri using request dispatcher.
* This method is used by all internal method needi
- * @param uri Uri of page to include
+ * @param uri Context-relative URI to include
* @param request Current page request
* @param response Current page response
* @since Struts 1.1
1.23 +14 -3 jakarta-struts/web/example/WEB-INF/struts-config.xml
Index: struts-config.xml
===================================================================
RCS file: /home/cvs/jakarta-struts/web/example/WEB-INF/struts-config.xml,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- struts-config.xml 16 Jun 2002 04:43:19 -0000 1.22
+++ struts-config.xml 5 Jul 2002 22:09:21 -0000 1.23
@@ -72,6 +72,7 @@
<global-forwards>
<forward name="logoff" path="/logoff.do"/>
<forward name="logon" path="/logon.jsp"/>
+ <forward name="registration" path="/registration.jsp"/>
<forward name="success" path="/mainMenu.jsp"/>
</global-forwards>
@@ -109,7 +110,7 @@
type="org.apache.struts.webapp.example.LogonAction"
name="logonForm"
scope="request"
- input="/logon.jsp">
+ input="logon">
<exception
key="expired.password"
type="org.apache.struts.webapp.example.ExpiredPasswordException"
@@ -121,14 +122,15 @@
type="org.apache.struts.webapp.example.SaveRegistrationAction"
name="registrationForm"
scope="request"
- input="/registration.jsp"/>
+ input="registration"/>
<!-- Save mail subscription -->
<action path="/saveSubscription"
type="org.apache.struts.webapp.example.SaveSubscriptionAction"
name="subscriptionForm"
scope="request"
- input="/subscription.jsp">
+ input="subscription">
+ <forward name="subscription" path="/subscription.jsp"/>
<forward name="success" path="/editRegistration.do?action=Edit"/>
</action>
@@ -139,6 +141,15 @@
</action>
</action-mappings>
+
+
+ <!-- ========== Controller Configuration ================================ -->
+
+ <controller>
+ <!-- The "input" parameter on "action" elements is the name of a
+ local or global "forward" rather than a subapp-relative path -->
+ <set-property property="inputForward" value="true"/>
+ </controller>
<!-- ========== Message Resources Definitions =========================== -->
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>