Revision: 653
          http://stripes.svn.sourceforge.net/stripes/?rev=653&view=rev
Author:   bengunter
Date:     2007-12-07 10:56:46 -0800 (Fri, 07 Dec 2007)

Log Message:
-----------
Fixed STS-289: @DontValidate should take a parameter to control what happens to 
validation errors from binding. Added ignoreBindingErrors element to 
@DontValidate with a default value of true. @DontValidate now causes Stripes to 
completely ignore validation errors no matter when they occur.

Modified Paths:
--------------
    trunk/stripes/src/net/sourceforge/stripes/action/DontValidate.java
    trunk/stripes/src/net/sourceforge/stripes/controller/DispatcherHelper.java

Modified: trunk/stripes/src/net/sourceforge/stripes/action/DontValidate.java
===================================================================
--- trunk/stripes/src/net/sourceforge/stripes/action/DontValidate.java  
2007-12-07 12:55:17 UTC (rev 652)
+++ trunk/stripes/src/net/sourceforge/stripes/action/DontValidate.java  
2007-12-07 18:56:46 UTC (rev 653)
@@ -21,15 +21,25 @@
 import java.lang.annotation.ElementType;
 
 /**
- * Marker annotation to specify that the event handled by the annotated method 
should not have
- * validation run on it before the handler is invoked.  In this case type 
conversion will still
- * occur, but all other forms of validation (including ActionBean.validate() 
if it exists) will
- * be by-passed.
- *
+ * Specify that the event handled by the annotated method should not have 
validation run on it
+ * before the handler is invoked. Note that even if there are no normal 
validation errors for a
+ * request, there may still be errors during type conversion and binding. Such 
errors are also
+ * ignored by default. That behavior can be modified using the [EMAIL 
PROTECTED] #ignoreBindingErrors()}
+ * element of this annotation.
+ * 
  * @author Tim Fennell
  */
 @Retention(RetentionPolicy.RUNTIME)
 @Target({ElementType.METHOD})
 @Documented
 public @interface DontValidate {
+    /**
+     * If true (the default) then any validation errors that might occur 
during type conversion and
+     * binding will be ignored. If false then Stripes will forward back to the 
source page as it
+     * normally would when it encounters validation errors. In either case, 
any errors that occur
+     * during binding will be present in the [EMAIL PROTECTED] 
ActionBeanContext}.
+     * 
+     * @see ActionBeanContext#getValidationErrors()
+     */
+    boolean ignoreBindingErrors() default true;
 }

Modified: 
trunk/stripes/src/net/sourceforge/stripes/controller/DispatcherHelper.java
===================================================================
--- trunk/stripes/src/net/sourceforge/stripes/controller/DispatcherHelper.java  
2007-12-07 12:55:17 UTC (rev 652)
+++ trunk/stripes/src/net/sourceforge/stripes/controller/DispatcherHelper.java  
2007-12-07 18:56:46 UTC (rev 653)
@@ -353,22 +353,27 @@
      *         should be processed in favor of continuing on to handler 
invocation
      */
     public static Resolution handleValidationErrors(ExecutionContext ctx) 
throws Exception {
-        ActionBean bean            = ctx.getActionBean();
-        ActionBeanContext context  = ctx.getActionBeanContext();
-        ValidationErrors errors    = context.getValidationErrors();
-        Resolution resolution = null;
+        DontValidate annotation = 
ctx.getHandler().getAnnotation(DontValidate.class);
+        boolean doValidate = annotation == null || 
!annotation.ignoreBindingErrors();
 
         // If we have errors, add the action path to them
         fillInValidationErrors(ctx);
 
-        // Now if we have errors and the bean wants to handle them...
-        if (errors.size() > 0 && bean instanceof ValidationErrorHandler) {
-            resolution = ((ValidationErrorHandler) 
bean).handleValidationErrors(errors);
-        }
+        Resolution resolution = null;
+        if (doValidate) {
+            ActionBean bean = ctx.getActionBean();
+            ActionBeanContext context = ctx.getActionBeanContext();
+            ValidationErrors errors = context.getValidationErrors();
 
-        // If there are still errors see if we need to lookup the resolution
-        if (errors.size() > 0 && resolution == null) {
-            resolution  = context.getSourcePageResolution();
+            // Now if we have errors and the bean wants to handle them...
+            if (errors.size() > 0 && bean instanceof ValidationErrorHandler) {
+                resolution = ((ValidationErrorHandler) 
bean).handleValidationErrors(errors);
+            }
+
+            // If there are still errors see if we need to lookup the 
resolution
+            if (errors.size() > 0 && resolution == null) {
+                resolution = context.getSourcePageResolution();
+            }
         }
 
         return resolution;


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
SF.Net email is sponsored by: 
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development

Reply via email to