You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by hl...@apache.org on 2010/03/20 04:00:06 UTC

svn commit: r925537 - in /tapestry/tapestry5/trunk/tapestry-core/src: main/java/org/apache/tapestry5/corelib/mixins/ test/app1/ test/java/org/apache/tapestry5/integration/app1/ test/java/org/apache/tapestry5/integration/app1/pages/

Author: hlship
Date: Sat Mar 20 03:00:05 2010
New Revision: 925537

URL: http://svn.apache.org/viewvc?rev=925537&view=rev
Log:
TAP5-1065: Non-visual mixin to generate events as it begins/ends rendering (useful for generating matching JavaScript)

Added:
    tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/mixins/RenderNotification.java   (with props)
    tapestry/tapestry5/trunk/tapestry-core/src/test/app1/RenderNotificationDemo.tml
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/RenderNotificationDemo.java   (with props)
Modified:
    tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/MixinTests.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/corelib/mixins/RenderNotification.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/mixins/RenderNotification.java?rev=925537&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/mixins/RenderNotification.java (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/mixins/RenderNotification.java Sat Mar 20 03:00:05 2010
@@ -0,0 +1,57 @@
+// 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.corelib.mixins;
+
+import org.apache.tapestry5.Block;
+import org.apache.tapestry5.ComponentResources;
+import org.apache.tapestry5.MarkupWriter;
+import org.apache.tapestry5.annotations.AfterRender;
+import org.apache.tapestry5.annotations.BeginRender;
+import org.apache.tapestry5.annotations.Events;
+import org.apache.tapestry5.ioc.annotations.Inject;
+
+/**
+ * This mixin triggers event notifcations to identify when it enters
+ * the {@link BeginRender} and {@link AfterRender} render phases.
+ * The {@link MarkupWriter} is passed as the event context. The most common use of this
+ * is to handle the "afterRender" event to generate client-side JavaScript for content
+ * just rendered via a {@link Block} (this is a common Ajax use case related to partial
+ * page rendering).
+ * 
+ * @since 5.2.0
+ */
+@Events(
+{ "beginRender", "afterRender" })
+public class RenderNotification
+{
+    @Inject
+    private ComponentResources resources;
+
+    void beginRender(MarkupWriter writer)
+    {
+        trigger(writer, "beginRender");
+    }
+
+    void afterRender(MarkupWriter writer)
+    {
+        trigger(writer, "afterRender");
+    }
+
+    private void trigger(MarkupWriter writer, String eventName)
+    {
+        resources.triggerEvent(eventName, new Object[]
+        { writer }, null);
+    }
+}

Propchange: tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/mixins/RenderNotification.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tapestry/tapestry5/trunk/tapestry-core/src/test/app1/RenderNotificationDemo.tml
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/RenderNotificationDemo.tml?rev=925537&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/app1/RenderNotificationDemo.tml (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/app1/RenderNotificationDemo.tml Sat Mar 20 03:00:05 2010
@@ -0,0 +1,9 @@
+<html t:type="Border" xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
+
+  <h1>RenderNotification Mixin Demo</h1>
+
+  <ul id="list">
+    <li t:type="any" t:id="item" t:mixins="rendernotification">item body in template</li>
+  </ul>
+
+</html>

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/MixinTests.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/MixinTests.java?rev=925537&r1=925536&r2=925537&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/MixinTests.java (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/MixinTests.java Sat Mar 20 03:00: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,
@@ -20,6 +20,15 @@ import org.testng.annotations.Test;
 public class MixinTests extends TapestryCoreTestCase
 {
     @Test
+    public void render_notification_mixin()
+    {
+        clickThru("RenderNotification Demo");
+
+        assertTextSeries("//ul[@id='list']//li[%d]", 1, "before item render", "item body in template",
+                "after item render");
+    }
+
+    @Test
     public void renderclientid_mixin()
     {
         clickThru("RenderClientId Mixin");
@@ -62,11 +71,10 @@ public class MixinTests extends Tapestry
         assertText("order7_after_but_before2", "3-after");
     }
 
-    private void assertMixinOrder(int orderNum, int echo1From, int echo2From, int echo3From,
-            int fieldFrom, boolean isField)
+    private void assertMixinOrder(int orderNum, int echo1From, int echo2From, int echo3From, int fieldFrom,
+            boolean isField)
     {
-        assertEchoMixins("order" + orderNum, "batman", echo1From, echo2From, echo3From, fieldFrom,
-                isField);
+        assertEchoMixins("order" + orderNum, "batman", echo1From, echo2From, echo3From, fieldFrom, isField);
     }
 
     /**
@@ -81,8 +89,8 @@ public class MixinTests extends Tapestry
      *                 "from" is < 0, checking the corresponding mixin values is disabled.
      */
 
-    private void assertEchoMixins(String fieldName, String originalValue, int echo1From,
-            int echo2From, int echo3From, int fieldFrom, boolean isField)
+    private void assertEchoMixins(String fieldName, String originalValue, int echo1From, int echo2From, int echo3From,
+            int fieldFrom, boolean isField)
     {
         String[] vals =
         { originalValue, "temporaryvaluefromechovaluemixin", "3", "world" };

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=925537&r1=925536&r2=925537&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 Sat Mar 20 03:00:05 2010
@@ -67,6 +67,8 @@ public class Index
     private static final List<Item> ITEMS = CollectionFactory
             .newList(
 
+                    new Item("RenderNotificationDemo", "RenderNotification Demo", "Use of RenderNotification mixin"),
+
                     new Item("InjectMessagesDemo", "Inject Global Messages into Service Demo",
                             "Ensure that it is possible to inject the application global message catalog into a service"),
 

Added: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/RenderNotificationDemo.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/RenderNotificationDemo.java?rev=925537&view=auto
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/RenderNotificationDemo.java (added)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/RenderNotificationDemo.java Sat Mar 20 03:00:05 2010
@@ -0,0 +1,34 @@
+// 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.MarkupWriter;
+
+public class RenderNotificationDemo
+{
+    void onBeginRenderFromItem(MarkupWriter writer)
+    {
+        writer.element("li");
+        writer.write("before item render");
+        writer.end();
+    }
+
+    void onAfterRender(MarkupWriter writer)
+    {
+        writer.element("li");
+        writer.write("after item render");
+        writer.end();
+    }
+}

Propchange: tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/RenderNotificationDemo.java
------------------------------------------------------------------------------
    svn:eol-style = native