On Fri, Apr 30, 2010 at 2:11 AM, Howard Lewis Ship <[email protected]> wrote:
> Question: what should the behavior be in the case where the method > throws a checked exception? As currently written, the persistent > field data will still be discarded ... is that what you want? > Good catch. I was not sure about the behavior in case of an exception and hoped to get some comments. Shall we keep the values in this case? We can also add a parameter saying what to do in case of an exception. The param would default to "keep values". > > Anyway ... as you can see, meta programming Java in Tapestry is now > really, really fun and easy! > Yes, Tapestry becomes more and more fun. > > Also, I think there's a documentation annotation for DiscardAfter to > identify that it is only used with components. > > On Thu, Apr 29, 2010 at 2:50 PM, <[email protected]> wrote: > > Author: drobiazko > > Date: Thu Apr 29 21:50:01 2010 > > New Revision: 939490 > > > > URL: http://svn.apache.org/viewvc?rev=939490&view=rev > > Log: > > TAP5-1121: Provide an annotation to support automatic discarding of the > persistent fields after a component or page method invocation > > > > Added: > > > > tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/annotations/DiscardAfter.java > (with props) > > > > tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/DiscardAfterWorker.java > (with props) > > > tapestry/tapestry5/trunk/tapestry-core/src/test/app1/DiscardAfterDemo.tml > > > > tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/DiscardAfterDemo.java > (with props) > > Modified: > > > > tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java > > > > 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/Index.java > > > > Added: > 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=939490&view=auto > > > ============================================================================== > > --- > tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/annotations/DiscardAfter.java > (added) > > +++ > tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/annotations/DiscardAfter.java > Thu Apr 29 21:50:01 2010 > > @@ -0,0 +1,37 @@ > > +// Copyright 2010 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. > > +// See the License for the specific language governing permissions and > > +// limitations under the License. > > + > > +package org.apache.tapestry5.annotations; > > + > > +import static java.lang.annotation.ElementType.METHOD; > > +import static java.lang.annotation.RetentionPolicy.RUNTIME; > > + > > +import java.lang.annotation.Documented; > > +import java.lang.annotation.Retention; > > +import java.lang.annotation.Target; > > + > > +/** > > + * 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. > > + * > > + * @see > org.apache.tapestry5.ComponentResources#discardPersistentFieldChanges() > > + * @since 5.2.0 > > + */ > > +...@target(METHOD) > > +...@retention(RUNTIME) > > +...@documented > > +public @interface DiscardAfter > > +{ > > + > > +} > > > > Propchange: > tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/annotations/DiscardAfter.java > > > ------------------------------------------------------------------------------ > > svn:eol-style = native > > > > Propchange: > tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/annotations/DiscardAfter.java > > > ------------------------------------------------------------------------------ > > svn:mime-type = text/plain > > > > Added: > 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=939490&view=auto > > > ============================================================================== > > --- > tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/DiscardAfterWorker.java > (added) > > +++ > tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/DiscardAfterWorker.java > Thu Apr 29 21:50:01 2010 > > @@ -0,0 +1,58 @@ > > +// Copyright 2010 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. > > +// See the License for the specific language governing permissions and > > + > > +package org.apache.tapestry5.internal.transform; > > + > > +import java.util.List; > > + > > +import org.apache.tapestry5.ComponentResources; > > +import org.apache.tapestry5.annotations.DiscardAfter; > > +import org.apache.tapestry5.model.MutableComponentModel; > > +import org.apache.tapestry5.services.ClassTransformation; > > +import org.apache.tapestry5.services.ComponentClassTransformWorker; > > +import org.apache.tapestry5.services.ComponentMethodAdvice; > > +import org.apache.tapestry5.services.ComponentMethodInvocation; > > +import org.apache.tapestry5.services.TransformMethod; > > + > > +public class DiscardAfterWorker implements ComponentClassTransformWorker > > +{ > > + > > + private final ComponentMethodAdvice advice = new > ComponentMethodAdvice() > > + { > > + > > + public void advise(ComponentMethodInvocation invocation) > > + { > > + invocation.proceed(); > > + > > + ComponentResources resources = > invocation.getComponentResources(); > > + > > + resources.discardPersistentFieldChanges(); > > + > > + } > > + > > + }; > > + > > + public void transform(final ClassTransformation transformation, > final MutableComponentModel model) > > + { > > + final List<TransformMethod> methods = > transformation.matchMethodsWithAnnotation(DiscardAfter.class); > > + > > + if (methods.isEmpty()) > > + return; > > + > > + for (final TransformMethod metod : methods) > > + { > > + metod.addAdvice(advice); > > + } > > + > > + } > > +} > > > > Propchange: > tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/DiscardAfterWorker.java > > > ------------------------------------------------------------------------------ > > svn:eol-style = native > > > > Propchange: > tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/DiscardAfterWorker.java > > > ------------------------------------------------------------------------------ > > svn:mime-type = text/plain > > > > Modified: > tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java > > URL: > http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java?rev=939490&r1=939489&r2=939490&view=diff > > > ============================================================================== > > --- > tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java > (original) > > +++ > tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TapestryModule.java > Thu Apr 29 21:50:01 2010 > > @@ -631,6 +631,8 @@ public final class TapestryModule > > > > configuration.add("Retain", new RetainWorker()); > > configuration.addInstance("Persist", PersistWorker.class); > > + > > + configuration.addInstance("DiscardAfter", > DiscardAfterWorker.class); > > > > configuration.addInstance("IncludeStylesheet", > IncludeStylesheetWorker.class, "after:SetupRender"); > > configuration > > > > Added: > 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=939490&view=auto > > > ============================================================================== > > --- > tapestry/tapestry5/trunk/tapestry-core/src/test/app1/DiscardAfterDemo.tml > (added) > > +++ > tapestry/tapestry5/trunk/tapestry-core/src/test/app1/DiscardAfterDemo.tml > Thu Apr 29 21:50:01 2010 > > @@ -0,0 +1,18 @@ > > +<html t:type="Border" > > + xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd"> > > + > > + > > + <h1>@DiscardAfter Demo</h1> > > + > > + <t:form> > > + > > + <t:textfield t:id="stringValue"/> > > + > > + <t:submit t:id="keep" value="Keep Values"/> > > + <t:submit t:id="discard" value="Discard Values"/> > > + </t:form> > > + > > + <p> > > + Value is: '${stringValue}' > > + </p> > > +</html> > > \ No newline at end of file > > > > 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=939490&r1=939489&r2=939490&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 > Thu Apr 29 21:50:01 2010 > > @@ -1436,4 +1436,21 @@ public class CoreBehaviorsTests extends > > > > assertText("status", "Application Catalog Working"); > > } > > + > > + /** TAP5-1121 */ > > + @Test > > + public void discard_after() > > + { > > + clickThru("@DiscardAfter Demo"); > > + > > + type("stringValue", "foo bar baz"); > > + > > + clickAndWait("//inp...@id='keep']"); > > + > > + assertTextPresent("Value is: 'foo bar baz'"); > > + > > + clickAndWait("//inp...@id='discard']"); > > + > > + assertTextPresent("Value is: ''"); > > + } > > } > > > > Added: > 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=939490&view=auto > > > ============================================================================== > > --- > tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/DiscardAfterDemo.java > (added) > > +++ > tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/DiscardAfterDemo.java > Thu Apr 29 21:50:01 2010 > > @@ -0,0 +1,32 @@ > > +// Copyright 2010 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. > > +// See the License for the specific language governing permissions and > > +// limitations under the License. > > +package org.apache.tapestry5.integration.app1.pages; > > + > > +import org.apache.tapestry5.annotations.DiscardAfter; > > +import org.apache.tapestry5.annotations.Persist; > > +import org.apache.tapestry5.annotations.Property; > > + > > + > > +public class DiscardAfterDemo > > +{ > > + @Property > > + @Persist > > + private String stringValue; > > + > > + @DiscardAfter > > + void onSelectedFromDiscard() > > + { > > + > > + } > > +} > > > > Propchange: > tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/DiscardAfterDemo.java > > > ------------------------------------------------------------------------------ > > svn:eol-style = native > > > > Propchange: > tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/DiscardAfterDemo.java > > > ------------------------------------------------------------------------------ > > svn:mime-type = text/plain > > > > Modified: > tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java > > URL: > http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java?rev=939490&r1=939489&r2=939490&view=diff > > > ============================================================================== > > --- > tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java > (original) > > +++ > tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java > Thu Apr 29 21:50:01 2010 > > @@ -430,7 +430,10 @@ public class Index > > "User represenation of enum values is > correctly read from messages"), > > > > new Item("unavailablecomponentdemo", "Report Location > of Unavailable Component", > > - "Report Location of Unavailable Component") > > + "Report Location of Unavailable Component"), > > + > > + new Item("discardafterdemo", "@DiscardAfter Demo", > > + "Demo using @DiscardAfter > annotation") > > > > ); > > > > > > > > > > > > -- > Howard M. Lewis Ship > > Creator of Apache Tapestry > > The source for Tapestry training, mentoring and support. Contact me to > learn how I can get you up and productive in Tapestry fast! > > (971) 678-5210 > http://howardlewisship.com > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > > -- Best regards, Igor Drobiazko http://tapestry5.de/blog
