You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by ge...@apache.org on 2004/09/02 23:39:18 UTC

cvs commit: jakarta-struts/contrib/struts-chain/src/java/org/apache/struts/chain/servlet ValidateActionForm.java

germuska    2004/09/02 14:39:18

  Modified:    contrib/struts-chain/src/java/org/apache/struts/chain/servlet
                        ValidateActionForm.java
  Log:
  Failed form validations were resulting in ActionErrors objects which were
  never being saved anywhere!
  
  I solved this with the possibly contentious solution of saving them directly
  in the validate() method.  I did this mostly to preserve the separation of
  servlet API specifics (the errors are saved in the HttpServletRequest scope).
  
  The only other alternative would be to add another abstract method to
  AbstractValidateActionForm, such as "saveErrors" but that seems kind of
  pedantic.
  
  Would it clear things up more to have validate return boolean and clearly give
  it the responsibility for "saving" any errors it finds?
  
  Revision  Changes    Path
  1.7       +12 -4     jakarta-struts/contrib/struts-chain/src/java/org/apache/struts/chain/servlet/ValidateActionForm.java
  
  Index: ValidateActionForm.java
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/contrib/struts-chain/src/java/org/apache/struts/chain/servlet/ValidateActionForm.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- ValidateActionForm.java	24 Jun 2004 01:27:31 -0000	1.6
  +++ ValidateActionForm.java	2 Sep 2004 21:39:18 -0000	1.7
  @@ -1,12 +1,12 @@
   /*
    * Copyright 2003,2004 The Apache Software Foundation.
  - * 
  + *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
    * You may obtain a copy of the License at
  - * 
  + *
    *      http://www.apache.org/licenses/LICENSE-2.0
  - * 
  + *
    * Unless required by applicable law or agreed to in writing, software
    * distributed under the License is distributed on an "AS IS" BASIS,
    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  @@ -26,6 +26,7 @@
   import org.apache.struts.action.ActionMapping;
   import org.apache.struts.chain.AbstractValidateActionForm;
   import org.apache.struts.config.ActionConfig;
  +import org.apache.struts.Globals;
   
   
   /**
  @@ -75,6 +76,13 @@
                   actionForm.getMultipartRequestHandler().rollback();
               }
           }
  +
  +        // Saving the errors is not part of the contract for this method,
  +        // but the idea of the HttpServletRequest is not present in the
  +        // abstract parent of this class.  Put this in now so that it
  +        // at least gets done -- and then see if other developers have
  +        // opinions about whether this is good, bad, or at least acceptable.
  +        swcontext.getRequest().setAttribute(Globals.ERROR_KEY, errors);
   
           return errors;
   
  
  
  

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