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/10/10 06:26:16 UTC

cvs commit: jakarta-struts/contrib/struts-chain/src/java/org/apache/struts/chain AbstractExecuteAction.java AbstractSelectInput.java AbstractValidateActionForm.java Constants.java CreateAction.java

craigmcc    2003/10/09 21:26:16

  Modified:    contrib/struts-chain/src/conf chain-config.xml
               contrib/struts-chain/src/java/org/apache/struts/chain
                        AbstractExecuteAction.java AbstractSelectInput.java
                        AbstractValidateActionForm.java Constants.java
                        CreateAction.java
  Log:
  As discussed on STRUTS-DEV, flatten the standard request processing chain
  so that validation failures store a success/failure state in the Context,
  which is then used by the SelectInput, CreateAction, and ExecuteAction
  commands to determine whether they should actually be performed or not.
  
  At the moment, the processing chain for exception handling is still
  modelled as a branch, because it seems likely that users will want to
  customize this path without wanting to mess with the normal lifecycle.
  
  Revision  Changes    Path
  1.5       +7 -25     jakarta-struts/contrib/struts-chain/src/conf/chain-config.xml
  
  Index: chain-config.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/contrib/struts-chain/src/conf/chain-config.xml,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- chain-config.xml	31 Aug 2003 22:42:45 -0000	1.4
  +++ chain-config.xml	10 Oct 2003 04:26:16 -0000	1.5
  @@ -135,8 +135,12 @@
   
         <!-- Validate the ActionForm for this request -->
         <command
  -          className="org.apache.struts.chain.servlet.ValidateActionForm"
  -     failureCommand="servlet-validation-failure"/>
  +          className="org.apache.struts.chain.servlet.ValidateActionForm"/>
  +
  +
  +      <!-- Select the appropriate ForwardConfig for return to input page -->
  +      <command
  +          className="org.apache.struts.chain.servlet.SelectInput"/>
   
   
         <!-- Create (if needed) the Action for this request -->
  @@ -173,28 +177,6 @@
         <!-- Execute the configured exception handler (if any) -->
         <command
             className="org.apache.struts.chain.servlet.ExceptionHandler"/>
  -
  -      <!-- Follow the returned ForwardConfig (if any) -->
  -      <command
  -          className="org.apache.struts.chain.servlet.PerformForward"/>
  -
  -    </chain>
  -
  -
  -    <!-- ========== Servlet Validation Failure Chain ======================= -->
  -
  -    <chain     name="servlet-validation-failure">
  -
  -      <!--
  -           This chain is designed to be invoked (by o.a.s.c.ValidateActionForm)
  -           if a validation failure occurs.  The standard behavior is to obey
  -           the "input" property of the current ActionConfig, and forward back
  -           to the input page.
  -      -->
  -
  -      <!-- Select the appropriate ForwardConfig for return to input page -->
  -      <command
  -          className="org.apache.struts.chain.servlet.SelectInput"/>
   
         <!-- Follow the returned ForwardConfig (if any) -->
         <command
  
  
  
  1.3       +35 -4     jakarta-struts/contrib/struts-chain/src/java/org/apache/struts/chain/AbstractExecuteAction.java
  
  Index: AbstractExecuteAction.java
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/contrib/struts-chain/src/java/org/apache/struts/chain/AbstractExecuteAction.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AbstractExecuteAction.java	29 Sep 2003 06:55:07 -0000	1.2
  +++ AbstractExecuteAction.java	10 Oct 2003 04:26:16 -0000	1.3
  @@ -89,6 +89,7 @@
       private String actionConfigKey = Constants.ACTION_CONFIG_KEY;
       private String actionFormKey = Constants.ACTION_FORM_KEY;
       private String forwardConfigKey = Constants.FORWARD_CONFIG_KEY;
  +    private String validKey = Constants.VALID_KEY;
   
   
       // -------------------------------------------------------------- Properties
  @@ -198,6 +199,30 @@
       }
   
   
  +    /**
  +     * <p>Return the context attribute key under which the
  +     * validity flag for this request is stored.</p>
  +     */
  +    public String getValidKey() {
  +
  +        return (this.validKey);
  +
  +    }
  +
  +
  +    /**
  +     * <p>Set the context attribute key under which the
  +     * validity flag for this request is stored.</p>
  +     *
  +     * @param validKey The new context attribute key
  +     */
  +    public void setValidKey(String validKey) {
  +
  +        this.validKey = validKey;
  +
  +    }
  +
  +
       // ---------------------------------------------------------- Public Methods
   
   
  @@ -213,6 +238,12 @@
        * @return <code>false</code> so that processing continues
        */
       public boolean execute(Context context) throws Exception {
  +
  +        // Skip processing if the current request is not valid
  +        Boolean valid = (Boolean) context.get(getValidKey());
  +        if ((valid == null) || !valid.booleanValue()) {
  +            return (false);
  +        }
   
           // Acquire the resources we will need to send to the Action
           Action action = (Action)
  
  
  
  1.3       +36 -4     jakarta-struts/contrib/struts-chain/src/java/org/apache/struts/chain/AbstractSelectInput.java
  
  Index: AbstractSelectInput.java
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/contrib/struts-chain/src/java/org/apache/struts/chain/AbstractSelectInput.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AbstractSelectInput.java	29 Sep 2003 06:55:07 -0000	1.2
  +++ AbstractSelectInput.java	10 Oct 2003 04:26:16 -0000	1.3
  @@ -88,6 +88,7 @@
   
       private String actionConfigKey = Constants.ACTION_CONFIG_KEY;
       private String forwardConfigKey = Constants.FORWARD_CONFIG_KEY;
  +    private String validKey = Constants.VALID_KEY;
   
       private static final Log log = LogFactory.getLog(AbstractSelectInput.class);
   
  @@ -147,6 +148,30 @@
       }
   
   
  +    /**
  +     * <p>Return the context attribute key under which the
  +     * validity flag for this request is stored.</p>
  +     */
  +    public String getValidKey() {
  +
  +        return (this.validKey);
  +
  +    }
  +
  +
  +    /**
  +     * <p>Set the context attribute key under which the
  +     * validity flag for this request is stored.</p>
  +     *
  +     * @param validKey The new context attribute key
  +     */
  +    public void setValidKey(String validKey) {
  +
  +        this.validKey = validKey;
  +
  +    }
  +
  +
       // ---------------------------------------------------------- Public Methods
   
   
  @@ -160,6 +185,13 @@
        */
       public boolean execute(Context context) throws Exception {
   
  +        // Skip processing if the current request is valid
  +        Boolean valid = (Boolean) context.get(getValidKey());
  +        if ((valid != null) && valid.booleanValue()) {
  +            return (false);
  +        }
  +
  +        // Acquire configuration objects that we need
           ActionConfig actionConfig = (ActionConfig)
               context.get(getActionConfigKey());
           ModuleConfig moduleConfig = actionConfig.getModuleConfig();
  
  
  
  1.4       +21 -30    jakarta-struts/contrib/struts-chain/src/java/org/apache/struts/chain/AbstractValidateActionForm.java
  
  Index: AbstractValidateActionForm.java
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/contrib/struts-chain/src/java/org/apache/struts/chain/AbstractValidateActionForm.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AbstractValidateActionForm.java	29 Sep 2003 06:55:07 -0000	1.3
  +++ AbstractValidateActionForm.java	10 Oct 2003 04:26:16 -0000	1.4
  @@ -96,7 +96,7 @@
       private String actionFormKey = Constants.ACTION_FORM_KEY;
       private String cancelKey = Constants.CANCEL_KEY;
       private String catalogKey = Constants.CATALOG_KEY;
  -    private String failureCommand = null;
  +    private String validKey = Constants.VALID_KEY;
   
       private static final Log log =
           LogFactory.getLog(AbstractValidateActionForm.class);
  @@ -206,25 +206,25 @@
   
   
       /**
  -     * <p>Return the name of the command to be executed
  -     * if a validation failure occurs.</p>
  +     * <p>Return the context attribute key under which the
  +     * validity flag for this request is stored.</p>
        */
  -    public String getFailureCommand() {
  +    public String getValidKey() {
   
  -        return (this.failureCommand);
  +        return (this.validKey);
   
       }
   
   
       /**
  -     * <p>Set the name of the command to be executed
  -     * if a validation failure occurs.</p>
  +     * <p>Set the context attribute key under which the
  +     * validity flag for this request is stored.</p>
        *
  -     * @param failureCommand The name of the chain to be executed
  +     * @param validKey The new context attribute key
        */
  -    public void setFailureCommand(String failureCommand) {
  +    public void setValidKey(String validKey) {
   
  -        this.failureCommand = failureCommand;
  +        this.validKey = validKey;
   
       }
   
  @@ -248,6 +248,7 @@
           ActionForm actionForm = (ActionForm)
               context.get(getActionFormKey());
           if (actionForm == null) {
  +            context.put(getValidKey(), Boolean.TRUE);
               return (false);
           }
   
  @@ -255,6 +256,7 @@
           Boolean cancel = (Boolean)
               context.get(getCancelKey());
           if ((cancel != null) && cancel.booleanValue()) {
  +            context.put(getValidKey(), Boolean.TRUE);
               return (false);
           }
   
  @@ -262,6 +264,7 @@
           ActionConfig actionConfig = (ActionConfig)
               context.get(getActionConfigKey());
           if (!actionConfig.getValidate()) {
  +            context.put(getValidKey(), Boolean.TRUE);
               return (false);
           }
   
  @@ -270,25 +273,13 @@
   
           // If there were no errors, proceed normally
           if ((errors == null) || (errors.isEmpty())) {
  +            context.put(getValidKey(), Boolean.TRUE);
               return (false);
           }
   
  -        // Execute the specified validation failure command
  -        try {
  -            Catalog catalog = (Catalog)
  -                context.get(getCatalogKey());
  -            Command command = catalog.getCommand(getFailureCommand());
  -            if (log.isTraceEnabled()) {
  -                log.trace("Calling failure command '" + getFailureCommand()
  -                          + "'");
  -            }
  -            command.execute(context);
  -        } catch (Exception e) {
  -            log.warn("Exception from failure command '" +
  -                     getFailureCommand() + "'", e);
  -            throw new IllegalStateException("Failure chain threw exception");
  -        }
  -        return (true);
  +        // Flag the validation failure and proceed
  +        context.put(getValidKey(), Boolean.FALSE);
  +        return (false);
   
       }
   
  
  
  
  1.4       +11 -3     jakarta-struts/contrib/struts-chain/src/java/org/apache/struts/chain/Constants.java
  
  Index: Constants.java
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/contrib/struts-chain/src/java/org/apache/struts/chain/Constants.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Constants.java	31 Aug 2003 21:53:00 -0000	1.3
  +++ Constants.java	10 Oct 2003 04:26:16 -0000	1.4
  @@ -157,6 +157,14 @@
       public static final String MODULE_CONFIG_KEY = "moduleConfig";
   
   
  +    /**
  +     * <p>The default context attribute key under which a <code>Boolean</code>
  +     * is stored, indicating the valid state of the current request.  If not
  +     * present, a value of <code>Boolean.FALSE</code> should be assumed.
  +     */
  +    public static final String VALID_KEY = "valid";
  +
  +
       // --------------------------------------------------------- Other Constants
   
   
  
  
  
  1.3       +35 -4     jakarta-struts/contrib/struts-chain/src/java/org/apache/struts/chain/CreateAction.java
  
  Index: CreateAction.java
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/contrib/struts-chain/src/java/org/apache/struts/chain/CreateAction.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CreateAction.java	29 Sep 2003 06:55:07 -0000	1.2
  +++ CreateAction.java	10 Oct 2003 04:26:16 -0000	1.3
  @@ -92,6 +92,7 @@
       private String actionKey = Constants.ACTION_KEY;
       private String actionConfigKey = Constants.ACTION_CONFIG_KEY;
       private String actionServletKey = Constants.ACTION_SERVLET_KEY;
  +    private String validKey = Constants.VALID_KEY;
   
   
       // -------------------------------------------------------------- Properties
  @@ -175,6 +176,30 @@
       }
   
   
  +    /**
  +     * <p>Return the context attribute key under which the
  +     * validity flag for this request is stored.</p>
  +     */
  +    public String getValidKey() {
  +
  +        return (this.validKey);
  +
  +    }
  +
  +
  +    /**
  +     * <p>Set the context attribute key under which the
  +     * validity flag for this request is stored.</p>
  +     *
  +     * @param validKey The new context attribute key
  +     */
  +    public void setValidKey(String validKey) {
  +
  +        this.validKey = validKey;
  +
  +    }
  +
  +
       // ---------------------------------------------------------- Public Methods
   
   
  @@ -187,6 +212,12 @@
        * @return <code>false</code> so that processing continues
        */
       public boolean execute(Context context) throws Exception {
  +
  +        // Skip processing if the current request is not valid
  +        Boolean valid = (Boolean) context.get(getValidKey());
  +        if ((valid == null) || !valid.booleanValue()) {
  +            return (false);
  +        }
   
           // Look up the class name for the desired Action
           ActionConfig actionConfig = (ActionConfig)
  
  
  

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