Author: hlship
Date: Mon Jul 28 10:58:45 2008
New Revision: 680424

URL: http://svn.apache.org/viewvc?rev=680424&view=rev
Log:
TAPESTRY-2534: An event context should be passed through the Ajax request when 
AjaxFormLoop adds a new row

Modified:
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/AjaxFormLoop.java
    
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/AjaxFormLoop.tml
    tapestry/tapestry5/trunk/tapestry-core/src/test/app1/FormInjectorDemo.tml
    
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/FormInjectorDemo.java

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/AjaxFormLoop.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/AjaxFormLoop.java?rev=680424&r1=680423&r2=680424&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/AjaxFormLoop.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/corelib/components/AjaxFormLoop.java
 Mon Jul 28 10:58:45 2008
@@ -29,6 +29,7 @@
 import java.io.Serializable;
 import java.util.Collections;
 import java.util.Iterator;
+import java.util.List;
 
 /**
  * A special form of the [EMAIL PROTECTED] 
org.apache.tapestry5.corelib.components.Loop} component that adds a lot of Ajax 
support
@@ -57,6 +58,16 @@
     @Parameter(required = true)
     private Object value;
 
+
+    /**
+     * The context for the form loop (optional parameter). This list of values 
will be converted into strings and
+     * included in the URI. The strings will be coerced back to whatever their 
values are and made available to event
+     * handler methods.
+     */
+    @Parameter
+    private List<?> context;
+
+
     /**
      * A block to render after the loop as the body of the [EMAIL PROTECTED] 
org.apache.tapestry5.corelib.components.FormInjector}.
      * This typically contains a [EMAIL PROTECTED] 
org.apache.tapestry5.corelib.components.AddRowLink}.
@@ -120,7 +131,7 @@
 
     private boolean renderingInjector;
 
-    private final AjaxFormLoopContext context = new AjaxFormLoopContext()
+    private final AjaxFormLoopContext formLoopContext = new 
AjaxFormLoopContext()
     {
         public void addAddRowTrigger(String clientId)
         {
@@ -256,7 +267,7 @@
         }
     };
 
-    @SuppressWarnings({ "unchecked" })
+    @SuppressWarnings({"unchecked"})
     @Log
     private void syncValue(Serializable id)
     {
@@ -291,7 +302,7 @@
     /**
      * Uses the [EMAIL PROTECTED] org.apache.tapestry5.PrimaryKeyEncoder} to 
convert the current row value to an id.
      */
-    @SuppressWarnings({ "unchecked" })
+    @SuppressWarnings({"unchecked"})
     private Serializable idForCurrentValue()
     {
         return encoder.toKey(value);
@@ -313,7 +324,7 @@
 
     private void pushContext()
     {
-        environment.push(AjaxFormLoopContext.class, context);
+        environment.push(AjaxFormLoopContext.class, formLoopContext);
     }
 
     boolean beginRender(MarkupWriter writer)
@@ -363,7 +374,7 @@
      * a new row, and to return that new entity for rendering.
      */
     @Log
-    Object onActionFromRowInjector()
+    Object onActionFromRowInjector(EventContext context)
     {
         ComponentEventCallback callback = new ComponentEventCallback()
         {
@@ -375,7 +386,7 @@
             }
         };
 
-        resources.triggerEvent("addRow", null, callback);
+        resources.triggerContextEvent("addRow", context, callback);
 
         if (value == null)
             throw new IllegalArgumentException(
@@ -410,7 +421,7 @@
 
         Object value = encoder.toValue(coerced);
 
-        resources.triggerEvent("removeRow", new Object[] { value }, null);
+        resources.triggerEvent("removeRow", new Object[]{value}, null);
 
         return new JSONObject();
     }

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/AjaxFormLoop.tml
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/AjaxFormLoop.tml?rev=680424&r1=680423&r2=680424&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/AjaxFormLoop.tml
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/resources/org/apache/tapestry5/corelib/components/AjaxFormLoop.tml
 Mon Jul 28 10:58:45 2008
@@ -5,7 +5,7 @@
     </t:formfragment>
 
     <t:block id="tail">
-        <t:forminjector element="prop:element" t:id="rowInjector">
+        <t:forminjector element="prop:element" t:id="rowInjector" 
context="inherit:context">
             <t:delegate to="prop:addRow"/>
             <t:block id="defaultAddRow">
                 <t:addrowlink>Add row</t:addrowlink>

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/test/app1/FormInjectorDemo.tml
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/FormInjectorDemo.tml?rev=680424&r1=680423&r2=680424&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/app1/FormInjectorDemo.tml 
(original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/app1/FormInjectorDemo.tml 
Mon Jul 28 10:58:45 2008
@@ -5,7 +5,8 @@
     <t:form>
 
         <ul>
-            <li t:id="loop" t:type="AjaxFormLoop" source="doubleItems" 
value="item" encoder="encoder">
+            <li t:id="loop" t:type="AjaxFormLoop" source="doubleItems" 
value="item" encoder="encoder"
+                context="demoContextValue">
                 <t:submitnotifier>
                     <t:textfield t:id="value" value="item.value"/>
                     <t:removerowlink>remove</t:removerowlink>

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/FormInjectorDemo.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/FormInjectorDemo.java?rev=680424&r1=680423&r2=680424&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/FormInjectorDemo.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/FormInjectorDemo.java
 Mon Jul 28 10:58:45 2008
@@ -20,6 +20,7 @@
 import org.apache.tapestry5.annotations.Property;
 import org.apache.tapestry5.integration.app1.data.DoubleItem;
 import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
+import org.testng.Assert;
 
 import java.util.Collections;
 import java.util.Comparator;
@@ -29,6 +30,8 @@
 
 public class FormInjectorDemo
 {
+    private static final long DEMO_CONTEXT_VALUE = System.currentTimeMillis();
+
     @Property
     private DoubleItem item;
 
@@ -68,6 +71,11 @@
         };
     }
 
+    public long getDemoContextValue()
+    {
+        return DEMO_CONTEXT_VALUE;
+    }
+
     @Log
     public List<DoubleItem> getDoubleItems()
     {
@@ -78,8 +86,11 @@
         return items;
     }
 
-    Object onAddRow()
+    Object onAddRow(long context)
     {
+        Assert.assertEquals(context, DEMO_CONTEXT_VALUE,
+                            "Context value provided to AjaxFormLoop must be 
provided to the event handler method.");
+
         DoubleItem item = new DoubleItem();
         item.setId(ID_ALLOCATOR.incrementAndGet());
 


Reply via email to