Author: hlship
Date: Fri Jul 2 23:33:05 2010
New Revision: 960135
URL: http://svn.apache.org/viewvc?rev=960135&view=rev
Log:
TAP5-1198: A user defined activate event handler appears to execute *before*
the event handler supplied by @PageActivationContext, making defensive coding
impossible
Added:
tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/MissingPageActivationContext.groovy
- copied, changed from r958655,
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/music/MusicDetails2.java
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/PageActivationContextWorker.java
tapestry/tapestry5/trunk/tapestry-core/src/test/app1/Index.tml
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/Index.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/music/MusicDetails2.java
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/PageActivationContextWorker.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/PageActivationContextWorker.java?rev=960135&r1=960134&r2=960135&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/PageActivationContextWorker.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/PageActivationContextWorker.java
Fri Jul 2 23:33:05 2010
@@ -27,6 +27,7 @@ import org.apache.tapestry5.services.Com
import org.apache.tapestry5.services.FieldAccess;
import org.apache.tapestry5.services.TransformConstants;
import org.apache.tapestry5.services.TransformField;
+import org.apache.tapestry5.services.TransformMethod;
/**
* Provides the page activation context handlers. This worker must be
scheduled before
@@ -39,7 +40,6 @@ public class PageActivationContextWorker
{
public void transform(ClassTransformation transformation,
MutableComponentModel model)
{
-
List<TransformField> fields =
transformation.matchFieldsWithAnnotation(PageActivationContext.class);
// In the future we may add rules for ordering the fields (new
attribute on annotation?)
@@ -55,48 +55,42 @@ public class PageActivationContextWorker
}
}
- private void transformField(ClassTransformation transformation,
MutableComponentModel model,
- final TransformField field)
+ private void transformField(ClassTransformation transformation,
MutableComponentModel model, TransformField field)
{
- final PageActivationContext annotation =
field.getAnnotation(PageActivationContext.class);
+ PageActivationContext annotation =
field.getAnnotation(PageActivationContext.class);
- ComponentMethodAdvice advice = createAdvice(field, annotation);
+ TransformMethod dispatchEventMethod = transformation
+
.getOrCreateMethod(TransformConstants.DISPATCH_COMPONENT_EVENT);
-
transformation.getOrCreateMethod(TransformConstants.DISPATCH_COMPONENT_EVENT).addAdvice(advice);
+ FieldAccess access = field.getAccess();
if (annotation.activate())
+ {
+
dispatchEventMethod.addAdvice(createActivateAdvice(field.getType(), access));
model.addEventHandler(EventConstants.ACTIVATE);
+ }
if (annotation.passivate())
+ {
+ dispatchEventMethod.addAdvice(createPassivateAdvice(access));
model.addEventHandler(EventConstants.PASSIVATE);
+ }
// We don't claim the field, and other workers may even replace it
with a FieldValueConduit.
}
- private ComponentMethodAdvice createAdvice(TransformField field, final
PageActivationContext annotation)
+ private static ComponentMethodAdvice createActivateAdvice(final String
fieldType, final FieldAccess access)
{
- final String fieldType = field.getType();
- final FieldAccess access = field.getAccess();
-
return new ComponentMethodAdvice()
{
public void advise(ComponentMethodInvocation invocation)
{
- invocation.proceed();
-
ComponentEvent event = (ComponentEvent)
invocation.getParameter(0);
if (event.isAborted())
return;
- handleActivateEvent(event, invocation);
-
- handlePassivateEvent(event, invocation);
- }
-
- private void handleActivateEvent(ComponentEvent event,
ComponentMethodInvocation invocation)
- {
- if (annotation.activate() &&
event.matches(EventConstants.ACTIVATE, "", 1))
+ if (event.matches(EventConstants.ACTIVATE, "", 1))
{
event.setMethodDescription(access.toString());
@@ -106,12 +100,24 @@ public class PageActivationContextWorker
invocation.overrideResult(true);
}
+
+ invocation.proceed();
}
+ };
+ }
- private void handlePassivateEvent(ComponentEvent event,
ComponentMethodInvocation invocation)
+ private static ComponentMethodAdvice createPassivateAdvice(final
FieldAccess access)
+ {
+ return new ComponentMethodAdvice()
+ {
+ public void advise(ComponentMethodInvocation invocation)
{
+ ComponentEvent event = (ComponentEvent)
invocation.getParameter(0);
+
+ if (event.isAborted())
+ return;
- if (annotation.passivate() &&
event.matches(EventConstants.PASSIVATE, "", 0))
+ if (event.matches(EventConstants.PASSIVATE, "", 0))
{
event.setMethodDescription(access.toString());
@@ -121,6 +127,8 @@ public class PageActivationContextWorker
invocation.overrideResult(true);
}
+
+ invocation.proceed();
}
};
}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/app1/Index.tml
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/Index.tml?rev=960135&r1=960134&r2=960135&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/app1/Index.tml (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/app1/Index.tml Fri Jul 2
23:33:05 2010
@@ -2,6 +2,13 @@
<h1>Tapestry 5 Integration Application 1</h1>
+ <t:if test="alert">
+ <p>
+ Alert:
+ <em id="alert">${alert}</em>
+ </p>
+ </t:if>
+
<p>${items.size()} standard test pages</p>
<ul>
@@ -19,7 +26,8 @@
<li>
<a href="${injectDemoLink}">PageLink via Class Demo</a>
-- use ComponentResources to generate a link to a page using target
- page class, not logical page name
+ page class, not logical
+ page name
</li>
<li>
@@ -101,7 +109,8 @@
<li>
<a href="PublishDuplicateNameDemo">Duplicate Published Parameter Name</a>
-- demo error checking for the same parameter name published from two
different
- embedded components
+ embedded
+ components
</li>
<li>
<a href="EmbeddedComponentTypeConflict">Embedded Component Type Conflict
@@ -147,10 +156,14 @@
<a href="InvalidComponentTypeDemo">Invalid Component Type</a>
-- unknown type of component in template
</li>
- <li>
- <a href="NoTypeProvidedDemo">No Component Type Provided</a> --
- component type not defined.
- </li>
+ <li>
+ <a href="NoTypeProvidedDemo">No Component Type Provided</a>
+ --
+ component type not defined.
+ </li>
+ <li>
+ <a href="music/details2">Missing page activation context</a>
+ </li>
</ul>
</html>
Copied:
tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/MissingPageActivationContext.groovy
(from r958655,
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/music/MusicDetails2.java)
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/MissingPageActivationContext.groovy?p2=tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/MissingPageActivationContext.groovy&p1=tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/music/MusicDetails2.java&r1=958655&r2=960135&rev=960135&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/music/MusicDetails2.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/test/groovy/org/apache/tapestry5/integration/app1/MissingPageActivationContext.groovy
Fri Jul 2 23:33:05 2010
@@ -1,4 +1,4 @@
-// Copyright 2008 The Apache Software Foundation
+// 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.
@@ -12,16 +12,19 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-package org.apache.tapestry5.integration.app1.pages.music;
+package org.apache.tapestry5.integration.app1
+import org.apache.tapestry5.integration.TapestryCoreTestCase;
+import org.testng.annotations.Test;
-import org.apache.tapestry5.annotations.PageActivationContext;
-import org.apache.tapestry5.annotations.Property;
-import org.apache.tapestry5.integration.app1.data.Track;
-
-public class MusicDetails2
+class MissingPageActivationContext extends TapestryCoreTestCase
{
- @Property
- @PageActivationContext
- private Track track;
+ @Test
+ void page_activation_context_omitted_from_url() {
+ clickThru "Missing page activation context"
+
+ // Back to Index page, with alert message.
+
+ assertText "alert", "Track not specified in URL."
+ }
}
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=960135&r1=960134&r2=960135&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
Fri Jul 2 23:33:05 2010
@@ -20,7 +20,9 @@ import java.util.List;
import org.apache.tapestry5.ComponentResources;
import org.apache.tapestry5.Link;
+import org.apache.tapestry5.PersistenceConstants;
import org.apache.tapestry5.annotations.InjectPage;
+import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
@@ -30,6 +32,9 @@ import org.apache.tapestry5.ioc.internal
*/
public class Index
{
+ @Persist(PersistenceConstants.FLASH)
+ private String alert;
+
public static class Item implements Comparable<Item>
{
private final String pageName;
@@ -69,7 +74,7 @@ public class Index
new Item("ActivationRequestParameterDemo",
"ActivationRequestParameter Annotation Demo",
"Use of @ActivationRequestParameter to encode page
state into query parameters"),
-
+
new Item("LibraryMessagesDemo", "Library Messages Demo",
"Demo ability to contribute additional message
catalog resources to the application global catalog."),
@@ -481,4 +486,14 @@ public class Index
{
return new Music();
}
+
+ public void setAlert(String alert)
+ {
+ this.alert = alert;
+ }
+
+ public String getAlert()
+ {
+ return alert;
+ }
}
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/music/MusicDetails2.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/music/MusicDetails2.java?rev=960135&r1=960134&r2=960135&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/music/MusicDetails2.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/music/MusicDetails2.java
Fri Jul 2 23:33:05 2010
@@ -4,7 +4,7 @@
// 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
+// 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,
@@ -14,14 +14,29 @@
package org.apache.tapestry5.integration.app1.pages.music;
-
+import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.PageActivationContext;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.integration.app1.data.Track;
+import org.apache.tapestry5.integration.app1.pages.Index;
public class MusicDetails2
{
@Property
@PageActivationContext
private Track track;
+
+ @InjectPage
+ private Index index;
+
+ Object onActivate()
+ {
+ if (track == null)
+ {
+ index.setAlert("Track not specified in URL.");
+ return index;
+ }
+
+ return null;
+ }
}