You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by cr...@apache.org on 2003/02/16 03:51:33 UTC

cvs commit: jakarta-struts/src/share/org/apache/struts/action Action.java RequestProcessor.java

craigmcc    2003/02/15 18:51:32

  Modified:    src/share/org/apache/struts Globals.java
               src/share/org/apache/struts/action Action.java
                        RequestProcessor.java
  Log:
  Refactor the way that a cancelled request is detected so that it is not
  hard-wired to the request parameter name created by the standard Struts
  CancelTag key.  This behavior is totally backwards compatible.
  
  This change makes it possible for customized request processors for
  UI environments other than the standard Struts tags to easily indicate
  that the request has been cancelled, after recognizing whatever request
  parameter it wants to for this purpose.  (Yes, my use case is for a
  cancel button generated from a JavaServer Faces command button :-).
  
  Revision  Changes    Path
  1.5       +14 -4     jakarta-struts/src/share/org/apache/struts/Globals.java
  
  Index: Globals.java
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/Globals.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Globals.java	16 Nov 2002 06:03:06 -0000	1.4
  +++ Globals.java	16 Feb 2003 02:51:32 -0000	1.5
  @@ -114,6 +114,16 @@
   
   
       /**
  +     * <p>The request attributes key under which a boolean <code>true</code>
  +     * value should be stored if this request was cancelled.</p>
  +     *
  +     * @since Struts 1.1
  +     */
  +    public static final String CANCEL_KEY =
  +        "org.apache.struts.action.CANCEL";
  +
  +
  +    /**
        * <p>The base of the context attributes key under which our
        * <code>ModuleConfig</code> data structure will be stored.  This
        * will be suffixed with the actual module prefix (including the
  
  
  
  1.55      +13 -12    jakarta-struts/src/share/org/apache/struts/action/Action.java
  
  Index: Action.java
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/action/Action.java,v
  retrieving revision 1.54
  retrieving revision 1.55
  diff -u -r1.54 -r1.55
  --- Action.java	29 Dec 2002 22:09:40 -0000	1.54
  +++ Action.java	16 Feb 2003 02:51:32 -0000	1.55
  @@ -620,22 +620,23 @@
   
   
       /**
  -     * Returns <code>true</code> if the current form's cancel button was
  -     * pressed.  This method will check if the cancel button generated by
  -     * <strong>CancelTag</strong> was pressed by the user in the
  -     * current request.  If true, validation performed by an
  -     * <strong>ActionForm</strong> validate() method will have been
  -     * skipped by the controller servlet.
  +     * <p>Returns <code>true</code> if the current form's cancel button was
  +     * pressed.  This method will check if the <code>Globals.CANCEL_KEY</code>
  +     * request attribute has been set, which normally occurs if the cancel
  +     * button generated by <strong>CancelTag</strong> was pressed by the user
  +     * in the current request.  If <code>true</code>, validation performed
  +     * by an <strong>ActionForm</strong>'s <code>validate()</code> method
  +     * will have been skipped by the controller servlet.</p>
        *
        * @param request The servlet request we are processing
        * @see org.apache.struts.taglib.html.CancelTag
        */
       protected boolean isCancelled(HttpServletRequest request) {
   
  -    return ((request.getParameter(Constants.CANCEL_PROPERTY) != null) ||
  -                (request.getParameter(Constants.CANCEL_PROPERTY_X) != null));
  +        return (request.getAttribute(Globals.CANCEL_KEY) != null);
   
       }
  +
   
       /**
        * Return <code>true</code> if there is a transaction token stored in
  
  
  
  1.26      +23 -13    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.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- RequestProcessor.java	5 Feb 2003 05:30:13 -0000	1.25
  +++ RequestProcessor.java	16 Feb 2003 02:51:32 -0000	1.26
  @@ -781,7 +781,10 @@
   
       /**
        * Populate the properties of the specified ActionForm instance from
  -     * the request parameters included with this request.
  +     * the request parameters included with this request.  In addition,
  +     * request attribute <code>Globals.CANCEL_KEY</code> will be set if
  +     * the request was submitted with a button created by
  +     * <code>CancelTag</code>.
        *
        * @param request The servlet request we are processing
        * @param response The servlet response we are creating
  @@ -813,6 +816,12 @@
           RequestUtils.populate(form, mapping.getPrefix(), mapping.getSuffix(),
                                 request);
   
  +        // Set the cancellation request attribute if appropriate
  +        if ((request.getParameter(Constants.CANCEL_PROPERTY) != null) ||
  +            (request.getParameter(Constants.CANCEL_PROPERTY_X) != null)) {
  +            request.setAttribute(Globals.CANCEL_KEY, Boolean.TRUE);
  +        }
  +
       }
   
   
  @@ -882,11 +891,13 @@
   
   
       /**
  -     * Call the <code>validate()</code> method of the specified ActionForm,
  -     * and forward back to the input form if there are any errors.  Return
  -     * <code>true</code> if we should continue processing, or return
  -     * <code>false</code> if we have already forwarded control back to the
  -     * input form.
  +     * <p>If this request was not cancelled, and the request's
  +     * {@link ActionMapping} has not disabled validation, call the
  +     * <code>validate()</code> method of the specified {@link ActionForm},
  +     * and forward back to the input form if there were any errors.
  +     * Return <code>true</code> if we should continue processing,
  +     * or <code>false</code> if we have already forwarded control back
  +     * to the input form.</p>
        *
        * @param request The servlet request we are processing
        * @param response The servlet response we are creating
  @@ -906,9 +917,8 @@
               return (true);
           }
   
  -        // Was this submit cancelled?
  -        if ((request.getParameter(Constants.CANCEL_PROPERTY) != null) ||
  -            (request.getParameter(Constants.CANCEL_PROPERTY_X) != null)) {
  +        // Was this request cancelled?
  +        if (request.getAttribute(Globals.CANCEL_KEY) != null) {
               if (log.isDebugEnabled()) {
                   log.debug(" Cancelled transaction, skipping validation");
               }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-dev-help@jakarta.apache.org