DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=5966>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=5966

Add ActionForward as target for ActionForm

           Summary: Add ActionForward as target for ActionForm
           Product: Struts
           Version: Nightly Build
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Enhancement
          Priority: Other
         Component: Controller
        AssignedTo: [EMAIL PROTECTED]
        ReportedBy: [EMAIL PROTECTED]


Ted-

Here's the patch I've created...since the tld files are created through xslt
on the docs, I created the new doc entry so the build works.

Also, I'm not completely comfortable with the location of the "validation"
code (verifying that either action or forward is specified)...it needed to
happen before lookup, but it seemed inappropriate to add it to that method and I 
was
reluctant to change signatures of any protected methods.

'nuff said....here ya go.

Index: FormTag.java
===================================================================
RCS file:

/home/cvspublic/jakarta-struts/src/share/org/apache/struts/taglib/html/FormTag.j
ava,v
retrieving revision 1.15
diff -u -r1.15 FormTag.java
--- FormTag.java        2001/11/05 04:51:40     1.15
+++ FormTag.java        2001/11/11 16:34:03
@@ -81,8 +81,10 @@
  import org.apache.struts.action.ActionServlet;
  import org.apache.struts.util.MessageResources;
  import org.apache.struts.util.ResponseUtils;
+import org.apache.struts.action.ActionForwards;
+import org.apache.struts.action.ActionForward;
+import org.apache.struts.util.RequestUtils;

-
  /**
   * Custom tag that represents an input form, associated with a bean whose
   * properties correspond to the various fields of the form.
@@ -102,6 +104,10 @@
       */
      protected String action = null;

+    /**
+     * The global forward to which this form should be submitted.
+     */
+    protected String forward = null;

      /**
       * The content encoding to be used on a POST submit.
@@ -199,6 +205,12 @@
      protected String type = null;

+    /**
+     * The path this form should be submitted to, calculated based on
+     * the incoming <code>action</code> or <code>forward</code> attributes.
+     */
+    protected String actionPath = null;
+
      // -------------------------------------------------------------
Properties

@@ -223,8 +235,27 @@

      }

+    /**
+     * Return the global forward to which this form should be submitted
+     */
+    public String getForward() {
+
+      return this.forward;
+
+    }

      /**
+     * Set the global forward to which this form should be submitted
+     *
+     * @param forward the new global forward
+     */
+    public void setForward( String forward ) {
+
+      this.forward = forward;
+
+    }
+
+    /**
       * Return the focus field name for this form.
       */
      public String getFocus() {
@@ -420,9 +451,9 @@
          this.styleId = styleId;

      }
-

+
      /**
       * Return the window target.
       */
@@ -477,6 +508,16 @@
       */
      public int doStartTag() throws JspException {

+        // Ensure there's at least an "action" or "forward" attribute
+        if (action == null
+            && forward == null) {
+            JspException e = new JspException
+
(messages.getMessage("formTag.destination"));
+            pageContext.setAttribute(Action.EXCEPTION_KEY, e,
+                                     PageContext.REQUEST_SCOPE);
+            throw e;
+        }
+
          // Look up the form bean name, scope, and type if necessary
          lookup();

@@ -549,7 +590,7 @@
         // Store this tag itself as a page attribute
         pageContext.setAttribute(Constants.FORM_KEY, this,
                                   PageContext.REQUEST_SCOPE);
-
+
         // Locate or create the bean associated with our form
         int scope = PageContext.SESSION_SCOPE;
         if ("request".equals(this.scope))
@@ -654,6 +695,7 @@

         super.release();
         action = null;
+        forward = null;
         enctype = null;
         focus = null;
         method = "POST";
@@ -667,13 +709,35 @@
          styleId = null;
         target = null;
         type = null;
+        actionPath = null;

      }

      // ------------------------------------------------------ Protected
Methods

+    /**
+     * Return the raw path to which this form should be submitted
+     */
+    protected String getActionPath() {

+      if (actionPath == null) {
+        if (forward != null) {
+          ActionForwards forwards = (ActionForwards)
+                  pageContext.getAttribute(Action.FORWARDS_KEY,
+                                           PageContext.APPLICATION_SCOPE);
+          ActionForward af = forwards.findForward( forward );
+          actionPath = af.getPath();
+        } else {
+          actionPath = action;
+        }
+      }
+
+      return actionPath;
+    }
+
+
+
      /**
       * Return the form action converted into an action mapping path.  The
       * value of the <code>action</code> property is manipulated as follows
in
@@ -687,8 +751,8 @@
       */
      protected String getActionMappingName() {

-        String value = action;
-        int question = action.indexOf("?");
+        String value = getActionPath();
+        int question = value.indexOf("?");
          if (question >= 0)
              value = value.substring(0, question);
          int slash = value.lastIndexOf("/");
@@ -711,16 +775,16 @@
          HttpServletRequest request =
              (HttpServletRequest) pageContext.getRequest();
          StringBuffer value = new StringBuffer(request.getContextPath());
-
+
          // Use our servlet mapping, if one is specified
          String servletMapping = (String)
              pageContext.getAttribute(Action.SERVLET_KEY,
                                       PageContext.APPLICATION_SCOPE);
          if (servletMapping != null) {
              String queryString = null;
-            int question = action.indexOf("?");
+            int question = getActionPath().indexOf("?");
              if (question >= 0)
-                queryString = action.substring(question);
+                queryString = getActionPath().substring(question);
              String actionMapping = getActionMappingName();
              if (servletMapping.startsWith("*.")) {
                  value.append(actionMapping);
@@ -739,7 +803,7 @@
          else {
              if (!action.startsWith("/"))
                  value.append("/");
-            value.append(action);
+            value.append(getActionPath());
          }

          // Return the completed value

Index: struts-html.xml
===================================================================
RCS file: /home/cvspublic/jakarta-struts/doc/struts-html.xml,v
retrieving revision 1.25
diff -u -r1.25 struts-html.xml
--- struts-html.xml     2001/10/20 05:02:42     1.25
+++ struts-html.xml     2001/11/11 16:31:15
@@ -1178,7 +1178,7 @@

          <attribute>
              <name>action</name>
-            <required>true</required>
+            <required>false</required>
              <rtexprvalue>true</rtexprvalue>
              <info>
                          <p>The URL to which this form will be
submitted.  This
@@ -1196,6 +1196,9 @@
                          controller servlet, this value should be exactly
equal
                          to the <code>path</code> attribute of the
corresponding
                          <code>&lt;action&gt;</code> element.</p>
+
+                        You <b>must</b> specify exactly one of the
<code>forward</code>
+                        attribute or the <code>action</code> attribute.
                          </info>
          </attribute>

@@ -1219,6 +1222,18 @@
                  The field name (among the fields on this form) to which
initial
                  focus will be assigned with a JavaScript function. If not
specified,
                  no special JavaScript for this purpose will be rendered.
+            </info>
+        </attribute>
+
+        <attribute>
+            <name>forward</name>
+            <required>false</required>
+            <rtexprvalue>true</rtexprvalue>
+            <info>
+              Logical name of a global ActionForward that contains the
actual
+              content-relative URI of the destination of this transfer.
+              You <b>must</b> specify exactly one of the
<code>forward</code>
+              attribute or the <code>action</code> attribute.
              </info>
          </attribute>

  Index: LocalStrings.properties
===================================================================
RCS file:

/home/cvspublic/jakarta-struts/src/share/org/apache/struts/taglib/html/LocalStri
ngs.properties,v
retrieving revision 1.12
diff -u -r1.12 LocalStrings.properties
--- LocalStrings.properties     2001/10/16 15:43:58     1.12
+++ LocalStrings.properties     2001/11/11 16:42:42
@@ -5,6 +5,7 @@
  formTag.formBean=Cannot retrieve definition for form bean {0}
  formTag.mapping=Cannot retrieve mapping for action {0}
  formTag.nameType=Must specify type attribute if name is specified
+formTag.destination=You must specify exactly one of 'action' or 'forward'
  forwardTag.forward=Error forwarding to page {0}: {1}
  forwardTag.lookup=Cannot find global forward named {0}
  forwardTag.redirect=Error redirecting to path {0}: {1}

------- Additional Comments From [EMAIL PROTECTED]  2002-06-24 14:34 -------
is this something we want to go ahead and add and then close out this bug?  
what is our stance on "enhancements" for 1.1?

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to