Revision: 482
          http://svn.sourceforge.net/stripes/?rev=482&view=rev
Author:   bengunter
Date:     2007-03-04 09:13:02 -0800 (Sun, 04 Mar 2007)

Log Message:
-----------
Resolved STS-288: Add a @DontBind annotation to cause Stripes to skip binding 
and validation for specific events (e.g. cancel events)

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

Added Paths:
-----------
    trunk/stripes/src/net/sourceforge/stripes/action/DontBind.java

Added: trunk/stripes/src/net/sourceforge/stripes/action/DontBind.java
===================================================================
--- trunk/stripes/src/net/sourceforge/stripes/action/DontBind.java              
                (rev 0)
+++ trunk/stripes/src/net/sourceforge/stripes/action/DontBind.java      
2007-03-04 17:13:02 UTC (rev 482)
@@ -0,0 +1,37 @@
+/* Copyright 2005-2006 Tim Fennell
+ *
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sourceforge.stripes.action;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import net.sourceforge.stripes.controller.LifecycleStage;
+
+/**
+ * Marker annotation to specify that the event handled by the annotated method 
should skip
+ * [EMAIL PROTECTED] LifecycleStage#BindingAndValidation} altogether. This is 
useful for events which ignore
+ * user input, such as cancel events. Note that the presence of this 
annotation on an event handler
+ * implies [EMAIL PROTECTED] DontValidate} as well.
+ * 
+ * @author Ben Gunter
+ */
[EMAIL PROTECTED](RetentionPolicy.RUNTIME)
[EMAIL PROTECTED]( { ElementType.METHOD })
[EMAIL PROTECTED]
+public @interface DontBind {
+}

Modified: 
trunk/stripes/src/net/sourceforge/stripes/controller/DispatcherHelper.java
===================================================================
--- trunk/stripes/src/net/sourceforge/stripes/controller/DispatcherHelper.java  
2007-03-04 05:36:46 UTC (rev 481)
+++ trunk/stripes/src/net/sourceforge/stripes/controller/DispatcherHelper.java  
2007-03-04 17:13:02 UTC (rev 482)
@@ -16,6 +16,7 @@
 
 import net.sourceforge.stripes.action.ActionBean;
 import net.sourceforge.stripes.action.ActionBeanContext;
+import net.sourceforge.stripes.action.DontBind;
 import net.sourceforge.stripes.action.DontValidate;
 import net.sourceforge.stripes.action.Resolution;
 import net.sourceforge.stripes.config.Configuration;
@@ -175,18 +176,25 @@
     public static Resolution doBindingAndValidation(final ExecutionContext ctx,
                                                     final boolean validate) 
throws Exception {
         // Bind the value to the bean - this includes performing field level 
validation
-        final boolean doValidate = validate && 
ctx.getHandler().getAnnotation(DontValidate.class) == null;
+        final boolean doBind = ctx.getHandler().getAnnotation(DontBind.class) 
== null;
+        final boolean doValidate = doBind && validate && 
ctx.getHandler().getAnnotation(DontValidate.class) == null;
         final Configuration config = StripesFilter.getConfiguration();
-        ctx.setLifecycleStage(LifecycleStage.BindingAndValidation);
-        
ctx.setInterceptors(config.getInterceptors(LifecycleStage.BindingAndValidation));
+        
+        if (doBind) {
+            ctx.setLifecycleStage(LifecycleStage.BindingAndValidation);
+            
ctx.setInterceptors(config.getInterceptors(LifecycleStage.BindingAndValidation));
 
-        return ctx.wrap( new Interceptor() {
-            public Resolution intercept(ExecutionContext ctx) throws Exception 
{
-                ActionBeanPropertyBinder binder = 
config.getActionBeanPropertyBinder();
-                binder.bind(ctx.getActionBean(), ctx.getActionBeanContext(), 
doValidate);
-                return null;
-            }
-        });
+            return ctx.wrap(new Interceptor() {
+                public Resolution intercept(ExecutionContext ctx) throws 
Exception {
+                    ActionBeanPropertyBinder binder = 
config.getActionBeanPropertyBinder();
+                    binder.bind(ctx.getActionBean(), 
ctx.getActionBeanContext(), doValidate);
+                    return null;
+                }
+            });
+        }
+        else {
+            return null;
+        }
     }
 
     /**
@@ -202,13 +210,15 @@
                                                 final boolean 
alwaysInvokeValidate) throws Exception {
         final ValidationErrors errors = 
ctx.getActionBeanContext().getValidationErrors();
         final ActionBean bean = ctx.getActionBean();
-        final boolean doValidate = 
ctx.getHandler().getAnnotation(DontValidate.class) == null;
+        final boolean doBind = ctx.getHandler().getAnnotation(DontBind.class) 
== null;
+        final boolean doValidate = doBind && 
ctx.getHandler().getAnnotation(DontValidate.class) == null;
         Configuration config = StripesFilter.getConfiguration();
 
         // Run the bean's validate() method if the following conditions are 
met:
-        //   1. This event is not marked to bypass validation (doValidate == 
true)
-        //   2. The bean is an instance of Validatable
-        //   3. We have no errors so far OR alwaysInvokeValidate is true
+        //   l. This event is not marked to bypass binding 
+        //   2. This event is not marked to bypass validation (doValidate == 
true)
+        //   3. The bean is an instance of Validatable
+        //   4. We have no errors so far OR alwaysInvokeValidate is true
         if (doValidate) {
 
             ctx.setLifecycleStage(LifecycleStage.CustomValidation);


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

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development

Reply via email to