You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2009/02/26 19:24:13 UTC
svn commit: r748260 - in /tapestry/tapestry5/trunk/tapestry-core/src:
main/java/org/apache/tapestry5/internal/structure/
main/java/org/apache/tapestry5/internal/transform/
main/java/org/apache/tapestry5/runtime/
main/java/org/apache/tapestry5/services/...
Author: hlship
Date: Thu Feb 26 18:24:12 2009
New Revision: 748260
URL: http://svn.apache.org/viewvc?rev=748260&view=rev
Log:
TAP5-374: Persistent (@Persist) fields not set correctly between requests if they are initialised from pageAttached() method
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElementImpl.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/PageImpl.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/PersistWorker.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/runtime/PageLifecycleListener.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TransformConstants.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/bindings/DefaultComponent.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/structure/PageImplTest.java
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElementImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElementImpl.java?rev=748260&r1=748259&r2=748260&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElementImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/ComponentPageElementImpl.java Thu Feb 26 18:24:12 2009
@@ -67,6 +67,14 @@
private static final Block PLACEHOLDER_BLOCK = new PlaceholderBlock();
+ private static final ComponentCallback RESTORE_STATE_BEFORE_PAGE_ATTACH = new LifecycleNotificationComponentCallback()
+ {
+ public void run(Component component)
+ {
+ component.restoreStateBeforePageAttach();
+ }
+ };
+
private static final ComponentCallback CONTAINING_PAGE_DID_ATTACH = new LifecycleNotificationComponentCallback()
{
public void run(Component component)
@@ -728,6 +736,11 @@
}
}
+ public void restoreStateBeforePageAttach()
+ {
+ invoke(false, RESTORE_STATE_BEFORE_PAGE_ATTACH);
+ }
+
public void containingPageDidAttach()
{
invoke(false, CONTAINING_PAGE_DID_ATTACH);
@@ -1210,4 +1223,6 @@
{
return elementResources.createPageRenderLink(pageClass, override, context);
}
+
+
}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/PageImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/PageImpl.java?rev=748260&r1=748259&r2=748260&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/PageImpl.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/structure/PageImpl.java Thu Feb 26 18:24:12 2009
@@ -141,6 +141,9 @@
if (dirtyCount != 0) throw new IllegalStateException(StructureMessages.pageIsDirty(this));
for (PageLifecycleListener listener : listeners)
+ listener.restoreStateBeforePageAttach();
+
+ for (PageLifecycleListener listener : listeners)
listener.containingPageDidAttach();
}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/PersistWorker.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/PersistWorker.java?rev=748260&r1=748259&r2=748260&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/PersistWorker.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/transform/PersistWorker.java Thu Feb 26 18:24:12 2009
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2009 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.
@@ -41,6 +41,8 @@
* default when the page detaches</li> <ii>On changes to the active field, post the change via the {@link
* org.apache.tapestry5.internal.InternalComponentResources} </li> <li>When the page attaches, pull the persisted
* value for the field out of the {@link org.apache.tapestry5.services.PersistentFieldBundle}</li> </ul>
+ *
+ * @see org.apache.tapestry5.runtime.PageLifecycleListener#restoreStateBeforePageAttach()
*/
private void makeFieldPersistent(String fieldName, ClassTransformation transformation,
MutableComponentModel model)
@@ -78,7 +80,7 @@
transformation.addMethod(new TransformMethodSignature(Modifier.PRIVATE, "void", writeMethodName,
new String[]
- {fieldType}, null), builder.toString());
+ { fieldType }, null), builder.toString());
transformation.replaceWriteAccess(fieldName, writeMethodName);
@@ -111,7 +113,7 @@
builder.end();
transformation.extendMethod(
- TransformConstants.CONTAINING_PAGE_DID_ATTACH_SIGNATURE,
+ TransformConstants.RESTORE_STATE_BEFORE_PAGE_ATTACH_SIGNATURE,
builder.toString());
}
}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/runtime/PageLifecycleListener.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/runtime/PageLifecycleListener.java?rev=748260&r1=748259&r2=748260&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/runtime/PageLifecycleListener.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/runtime/PageLifecycleListener.java Thu Feb 26 18:24:12 2009
@@ -1,4 +1,4 @@
-// Copyright 2006 The Apache Software Foundation
+// Copyright 2006, 2009 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.
@@ -35,6 +35,13 @@
* Invoked when a page is first attached to the current request, giving components a chance to initialize for the
* current request.
*/
-
void containingPageDidAttach();
+
+ /**
+ * A kind of "pre-attach" phase allowing components to restore internal state before handling the actual attach;
+ * this is primarily used to restore persisted fields.
+ *
+ * @since 5.1.0.1
+ */
+ void restoreStateBeforePageAttach();
}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TransformConstants.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TransformConstants.java?rev=748260&r1=748259&r2=748260&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TransformConstants.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/TransformConstants.java Thu Feb 26 18:24:12 2009
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2009 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.
@@ -31,8 +31,8 @@
{
// Shared parameters of a whole bunch of lifecycle methods, representing the different
// component render states.
- private static final String[] RENDER_PHASE_METHOD_PARAMETERS = {MarkupWriter.class.getName(),
- Event.class.getName()};
+ private static final String[] RENDER_PHASE_METHOD_PARAMETERS = { MarkupWriter.class.getName(),
+ Event.class.getName() };
/**
* Signature for {@link org.apache.tapestry5.runtime.Component#dispatchComponentEvent(org.apache.tapestry5.runtime.ComponentEvent)}.
@@ -40,7 +40,7 @@
* @see org.apache.tapestry5.annotations.OnEvent
*/
public static final TransformMethodSignature DISPATCH_COMPONENT_EVENT = new TransformMethodSignature(
- Modifier.PUBLIC, "boolean", "dispatchComponentEvent", new String[] {ComponentEvent.class.getName()},
+ Modifier.PUBLIC, "boolean", "dispatchComponentEvent", new String[] { ComponentEvent.class.getName() },
null);
/**
@@ -68,6 +68,14 @@
"containingPageDidAttach");
/**
+ * Signature for {@link org.apache.tapestry5.runtime.PageLifecycleListener#restoreStateBeforePageAttach()}
+ *
+ * @since 5.1.0.1
+ */
+ public static final TransformMethodSignature RESTORE_STATE_BEFORE_PAGE_ATTACH_SIGNATURE = new TransformMethodSignature(
+ "restoreStateBeforePageAttach");
+
+ /**
* Signature for {@link org.apache.tapestry5.runtime.Component#setupRender(MarkupWriter, Event)}.
*
* @see org.apache.tapestry5.annotations.SetupRender
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/bindings/DefaultComponent.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/bindings/DefaultComponent.java?rev=748260&r1=748259&r2=748260&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/bindings/DefaultComponent.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/bindings/DefaultComponent.java Thu Feb 26 18:24:12 2009
@@ -1,4 +1,4 @@
-// Copyright 2006, 2008 The Apache Software Foundation
+// Copyright 2006, 2008, 2009 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.
@@ -83,4 +83,8 @@
public void containingPageDidLoad()
{
}
+
+ public void restoreStateBeforePageAttach()
+ {
+ }
}
Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/structure/PageImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/structure/PageImplTest.java?rev=748260&r1=748259&r2=748260&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/structure/PageImplTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/structure/PageImplTest.java Thu Feb 26 18:24:12 2009
@@ -135,10 +135,12 @@
@Test
public void attach_notification()
{
-
PageLifecycleListener listener1 = newPageLifecycle();
PageLifecycleListener listener2 = newPageLifecycle();
+ listener1.restoreStateBeforePageAttach();
+ listener2.restoreStateBeforePageAttach();
+
listener1.containingPageDidAttach();
listener2.containingPageDidAttach();