You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by dr...@apache.org on 2010/05/04 08:35:29 UTC

svn commit: r940742 - in /tapestry/tapestry5/trunk/tapestry-core/src: main/java/org/apache/tapestry5/annotations/ main/java/org/apache/tapestry5/internal/transform/ test/app1/ test/java/org/apache/tapestry5/integration/app1/ test/java/org/apache/tapest...

Author: drobiazko
Date: Tue May  4 06:35:28 2010
New Revision: 940742

URL: http://svn.apache.org/viewvc?rev=940742&view=rev
Log:
TAP5-1121: Provide an annotation to support automatic discarding of the persistent fields after a component or page method invocation

Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/annotations/DiscardAfter.java
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/DiscardAfterWorker.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/app1/DiscardAfterDemo.tml
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/CoreBehaviorsTests.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/DiscardAfterDemo.java

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/annotations/DiscardAfter.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/annotations/DiscardAfter.java?rev=940742&r1=940741&r2=940742&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/annotations/DiscardAfter.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/annotations/DiscardAfter.java Tue May  4 06:35:28 2010
@@ -16,14 +16,20 @@ package org.apache.tapestry5.annotations
 
 import static java.lang.annotation.ElementType.METHOD;
 import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import static org.apache.tapestry5.ioc.annotations.AnnotationUseContext.COMPONENT;
+import static org.apache.tapestry5.ioc.annotations.AnnotationUseContext.MIXIN;
+import static org.apache.tapestry5.ioc.annotations.AnnotationUseContext.PAGE;
 
 import java.lang.annotation.Documented;
 import java.lang.annotation.Retention;
 import java.lang.annotation.Target;
 
+import org.apache.tapestry5.ioc.annotations.UseWith;
+
 /**
  * Marks a method of a page or a component to discard all persistent field changes. The changes are
- * eliminated from persistent storage after the marked method is invoked.
+ * eliminated from persistent storage after the marked method is invoked. Any exception (runtime or checked) 
+ * thrown by annotated method will cause persistent fields to keep their values.
  * 
  * @see org.apache.tapestry5.ComponentResources#discardPersistentFieldChanges()
  * @since 5.2.0
@@ -31,6 +37,7 @@ import java.lang.annotation.Target;
 @Target(METHOD)
 @Retention(RUNTIME)
 @Documented
+@UseWith({COMPONENT,MIXIN,PAGE})
 public @interface DiscardAfter
 {
 

Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/DiscardAfterWorker.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/DiscardAfterWorker.java?rev=940742&r1=940741&r2=940742&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/DiscardAfterWorker.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/DiscardAfterWorker.java Tue May  4 06:35:28 2010
@@ -34,6 +34,9 @@ public class DiscardAfterWorker implemen
         {
             invocation.proceed();
             
+            if(invocation.isFail())
+                return;
+            
             ComponentResources resources = invocation.getComponentResources();
             
             resources.discardPersistentFieldChanges();

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/app1/DiscardAfterDemo.tml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/DiscardAfterDemo.tml?rev=940742&r1=940741&r2=940742&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/app1/DiscardAfterDemo.tml (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/app1/DiscardAfterDemo.tml Tue May  4 06:35:28 2010
@@ -10,6 +10,7 @@
 
         <t:submit t:id="keep" value="Keep Values"/>
         <t:submit t:id="discard" value="Discard Values"/>
+        <t:submit t:id="discardWithCheckedException" value="Discard Values With Checked Exception"/>
     </t:form>
 
     <p>

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/CoreBehaviorsTests.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/CoreBehaviorsTests.java?rev=940742&r1=940741&r2=940742&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/CoreBehaviorsTests.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/CoreBehaviorsTests.java Tue May  4 06:35:28 2010
@@ -1452,6 +1452,22 @@ public class CoreBehaviorsTests extends 
         clickAndWait("//input[@id='discard']");
         
         assertTextPresent("Value is: ''");
+        
+        //Once again
+        
+        type("stringValue", "barney quux");
+        
+        clickAndWait("//input[@id='keep']");
+        
+        assertTextPresent("Value is: 'barney quux'");
+        
+        clickAndWait("//input[@id='discardWithCheckedException']");
+        
+        assertTextPresent("Oops! Error occured");
+        
+        clickThru("@DiscardAfter Demo");
+        
+        assertTextPresent("Value is: 'barney quux'");
     }
     
     /** TAP5-1080 */

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/DiscardAfterDemo.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/DiscardAfterDemo.java?rev=940742&r1=940741&r2=940742&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/DiscardAfterDemo.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/DiscardAfterDemo.java Tue May  4 06:35:28 2010
@@ -13,6 +13,8 @@
 // limitations under the License.
 package org.apache.tapestry5.integration.app1.pages;
 
+import java.io.IOException;
+
 import org.apache.tapestry5.annotations.DiscardAfter;
 import org.apache.tapestry5.annotations.Persist;
 import org.apache.tapestry5.annotations.Property;
@@ -29,4 +31,10 @@ public class DiscardAfterDemo
     {
         
     }
+    
+    @DiscardAfter
+    void onSelectedFromDiscardWithCheckedException() throws IOException
+    {
+        throw new IOException("Oops! Error occured");
+    }
 }