Updated Branches:
  refs/heads/5.3 6a7894db6 -> ef93aff22

TAP5-2100: Fixed Zone-refresh component using wrong context on refresh


Project: http://git-wip-us.apache.org/repos/asf/tapestry-5/repo
Commit: http://git-wip-us.apache.org/repos/asf/tapestry-5/commit/ef93aff2
Tree: http://git-wip-us.apache.org/repos/asf/tapestry-5/tree/ef93aff2
Diff: http://git-wip-us.apache.org/repos/asf/tapestry-5/diff/ef93aff2

Branch: refs/heads/5.3
Commit: ef93aff22d44d03c55310e4435cb5ffd3161a8f3
Parents: 6a7894d
Author: Taha Hafeez Siddiqi <[email protected]>
Authored: Thu Apr 18 19:18:08 2013 +0530
Committer: Taha Hafeez Siddiqi <[email protected]>
Committed: Thu Apr 18 19:18:08 2013 +0530

----------------------------------------------------------------------
 .../tapestry5/corelib/mixins/ZoneRefresh.java      |    5 +-
 tapestry-core/src/test/app1/Index.tml              |    4 +
 .../src/test/app1/ZoneRefreshWithContext.tml       |   13 ++++
 .../integration/app1/ZoneRefreshTest.java          |   39 ++++++++++---
 .../app1/pages/ZoneRefreshWithContext.java         |   44 +++++++++++++++
 5 files changed, 95 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/ef93aff2/tapestry-core/src/main/java/org/apache/tapestry5/corelib/mixins/ZoneRefresh.java
----------------------------------------------------------------------
diff --git 
a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/mixins/ZoneRefresh.java
 
b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/mixins/ZoneRefresh.java
index 9e86351..18da6dc 100644
--- 
a/tapestry-core/src/main/java/org/apache/tapestry5/corelib/mixins/ZoneRefresh.java
+++ 
b/tapestry-core/src/main/java/org/apache/tapestry5/corelib/mixins/ZoneRefresh.java
@@ -17,6 +17,7 @@ package org.apache.tapestry5.corelib.mixins;
 import org.apache.tapestry5.BindingConstants;
 import org.apache.tapestry5.ComponentResources;
 import org.apache.tapestry5.EventConstants;
+import org.apache.tapestry5.EventContext;
 import org.apache.tapestry5.Link;
 import org.apache.tapestry5.annotations.AfterRender;
 import org.apache.tapestry5.annotations.Import;
@@ -93,10 +94,10 @@ public class ZoneRefresh
       return link.toAbsoluteURI();
    }
    
-   Object onZoneRefresh()
+   Object onZoneRefresh(EventContext eventContext)
    {
       CaptureResultCallback<Object> callback = new 
CaptureResultCallback<Object>();
-      resources.triggerEvent(EventConstants.REFRESH, context, callback);
+      resources.triggerContextEvent(EventConstants.REFRESH, eventContext, 
callback);
       
       if(callback.getResult() != null){
          return callback.getResult();

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/ef93aff2/tapestry-core/src/test/app1/Index.tml
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/app1/Index.tml 
b/tapestry-core/src/test/app1/Index.tml
index 4a8ac83..1a2edbb 100644
--- a/tapestry-core/src/test/app1/Index.tml
+++ b/tapestry-core/src/test/app1/Index.tml
@@ -153,6 +153,10 @@
         -- refreshes zone with an event handler returning zone
     </li>
     <li>
+        <a href="ZoneRefreshWithContext">Zone Refresh With Context</a>
+        -- refreshes zone with a context
+    </li>
+    <li>
         <a href="UnsupportedParameterBlockDemo">Unsupported Parameter Block 
Demo</a>
         -- informal block parameter to a component that does not support 
informal parameters
     </li>

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/ef93aff2/tapestry-core/src/test/app1/ZoneRefreshWithContext.tml
----------------------------------------------------------------------
diff --git a/tapestry-core/src/test/app1/ZoneRefreshWithContext.tml 
b/tapestry-core/src/test/app1/ZoneRefreshWithContext.tml
new file mode 100644
index 0000000..956daab
--- /dev/null
+++ b/tapestry-core/src/test/app1/ZoneRefreshWithContext.tml
@@ -0,0 +1,13 @@
+<html xmlns:t='http://tapestry.apache.org/schema/tapestry_5_1_0.xsd'>
+   <head>
+   </head>
+   
+   <body>
+      Using zone with context :
+      <span t:type='zone' t:mixins='zonerefresh' t:period='2' 
t:context='counter' id='zone' t:id='zone'>
+         ${changed}
+      </span>
+      <t:actionlink t:id='link' zone='zone'>Add</t:actionlink>
+   </body>
+   
+</html>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/ef93aff2/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/ZoneRefreshTest.java
----------------------------------------------------------------------
diff --git 
a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/ZoneRefreshTest.java
 
b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/ZoneRefreshTest.java
index e44b7b7..708279e 100644
--- 
a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/ZoneRefreshTest.java
+++ 
b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/ZoneRefreshTest.java
@@ -35,19 +35,42 @@ public class ZoneRefreshTest extends SeleniumTestCase
       checkZoneValues("zone", 3);
    }
 
+   @Test
+   public void test_if_zone_with_context_works() throws Exception
+   {
+      openBaseURL();
+      clickAndWait("link=Zone Refresh With Context");
+
+      // assert that counter value didn't changed
+      checkZoneValue("zone", "false");
+      checkZoneValue("zone", "false");
+
+      // increment counter
+      click("link=Add");
+      waitForAjaxRequestsToComplete(PAGE_LOAD_TIMEOUT);
+
+      // assert that counter value didn't changed
+      checkZoneValue("zone", "true");
+      checkZoneValue("zone", "true");
+   }
+
    private void checkZoneValues(String zone, int times) throws Exception
    {
       for(int i = 1; i <= times; ++i)
       {
-         //Wait for ajax call to begin
-         
waitForCondition("selenium.browserbot.getCurrentWindow().Ajax.activeRequestCount
 != 0", "20000");
-         
-         //Wait for ajax call from end
-         
waitForCondition("selenium.browserbot.getCurrentWindow().Ajax.activeRequestCount
 == 0", "20000");
-         
-         //Check the value changed
-         assertText(zone, String.valueOf(i));
+         checkZoneValue(zone, String.valueOf(i));
       }
    }
 
+   private void checkZoneValue(String zone, String expected)
+   {
+      //Wait for ajax call to begin
+      
waitForCondition("selenium.browserbot.getCurrentWindow().Ajax.activeRequestCount
 != 0", "20000");
+
+      //Wait for ajax call from end
+      
waitForCondition("selenium.browserbot.getCurrentWindow().Ajax.activeRequestCount
 == 0", "20000");
+
+      //Check the value changed
+      assertText(zone, expected);
+   }
 }

http://git-wip-us.apache.org/repos/asf/tapestry-5/blob/ef93aff2/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ZoneRefreshWithContext.java
----------------------------------------------------------------------
diff --git 
a/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ZoneRefreshWithContext.java
 
b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ZoneRefreshWithContext.java
new file mode 100644
index 0000000..ba459ee
--- /dev/null
+++ 
b/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/ZoneRefreshWithContext.java
@@ -0,0 +1,44 @@
+// Copyright 2013 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.Persist;
+import org.apache.tapestry5.annotations.Property;
+
+public class ZoneRefreshWithContext
+{
+    @Persist
+    @Property
+    private int counter;
+
+    @Persist
+    @Property
+    private boolean changed;
+
+    void setupRender()
+    {
+        counter = 0;
+    }
+
+    void onRefreshFromZone(int counter)
+    {
+        this.changed = this.counter != counter;
+    }
+
+    void onActionFromLink()
+    {
+        this.counter++;
+    }
+}
+

Reply via email to