tapestry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jkuhn...@apache.org
Subject svn commit: r544313 - in /tapestry/tapestry4/trunk/tapestry-framework/src: java/org/apache/tapestry/form/ test/org/apache/tapestry/form/
Date Mon, 04 Jun 2007 22:26:03 GMT
Author: jkuhnert
Date: Mon Jun  4 15:26:02 2007
New Revision: 544313

URL: http://svn.apache.org/viewvc?view=rev&rev=544313
Log:
Fixes TAPESTRY-1536.  LinkSubmit combination with AbstractSubmit handling of async params
was causing duplicate events to be connected to onclick event.

Modified:
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/AbstractSubmit.java
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/LinkSubmit.java
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/Submit.jwc
    tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/LinkSubmitTest.java
    tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/TestSubmit.java

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/AbstractSubmit.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/AbstractSubmit.java?view=diff&rev=544313&r1=544312&r2=544313
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/AbstractSubmit.java
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/AbstractSubmit.java
Mon Jun  4 15:26:02 2007
@@ -130,14 +130,13 @@
             json.put("async", Boolean.TRUE);
             json.put("json", isJson());
             
-            DirectServiceParameter dsp = 
-                new DirectServiceParameter(form, null, this);
+            DirectServiceParameter dsp = new DirectServiceParameter(form, null, this);
             
             json.put("url", getDirectService().getLink(true, dsp).getURL());
         }
         
         if (!type.equals(FormConstants.SUBMIT_NORMAL)) {
-            if (!isParameterBound("onClick")
+            if (!isParameterBound("onClick") && !isParameterBound("onclick")
                 && (!isAsync() && (update == null || update.size() == 0)))
{
                 
                 StringBuffer str = new StringBuffer();
@@ -174,9 +173,27 @@
             
             PageRenderSupport prs = TapestryUtils.getPageRenderSupport(cycle, this);
             getSubmitScript().execute(this, cycle, prs, parms);
+
+            setSubmitBindingBound(true);
         }
     }
-    
+
+    /**
+     * Used internall to track whether or not an async submit binding was rendered
+     * as a result of calling {@link #renderSubmitBindings(org.apache.tapestry.IMarkupWriter,
org.apache.tapestry.IRequestCycle)}.
+     *
+     * <p>
+     * Currently this is used to track javascript contributions between the base and subclasses
so that
+     * duplicate client side bindings aren't created - such as the case with {@link LinkSubmit}
where
+     * client side javascript is always bound to the click of the link - with only the XHR
behaviour
+     * changing depending on the configuration of the component.
+     * </p>
+     *
+     * @return True if submit bindings have been configured for this component instance,
false otherwise.
+     */
+    public abstract boolean isSubmitBindingBound();
+    public abstract void setSubmitBindingBound(boolean value);
+
     /** parameter. */
     public abstract IActionListener getListener();
     
@@ -212,7 +229,9 @@
      * {@inheritDoc}
      */
     public abstract boolean isJson();
-    
+
+
+
     /** Injected. */
     public abstract IEngineService getDirectService();
     

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/LinkSubmit.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/LinkSubmit.java?view=diff&rev=544313&r1=544312&r2=544313
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/LinkSubmit.java
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/LinkSubmit.java
Mon Jun  4 15:26:02 2007
@@ -63,9 +63,7 @@
         String name = getName();
 
         if (!disabled)
-        {
-            PageRenderSupport pageRenderSupport = TapestryUtils.getPageRenderSupport(cycle,
this);
-            
+        {            
             writer.begin("a");
             writer.attribute("href", "#");
             
@@ -75,13 +73,20 @@
             
             renderSubmitBindings(writer, cycle);
 
-            Map symbols = new HashMap();
-            symbols.put("form", form);
-            symbols.put("name", name);
-            symbols.put("component", this);
-            symbols.put("functionName", ScriptUtils.functionHash("onclick" + this.hashCode()));
+            // only if superclass hasn't done it already
+            
+            if (!isSubmitBindingBound())
+            {
+                PageRenderSupport pageRenderSupport = TapestryUtils.getPageRenderSupport(cycle,
this);
+
+                Map symbols = new HashMap();
+                symbols.put("form", form);
+                symbols.put("name", name);
+                symbols.put("component", this);
+                symbols.put("functionName", ScriptUtils.functionHash("onclick" + this.hashCode()));
 
-            getScript().execute(this, cycle, pageRenderSupport, symbols);
+                getScript().execute(this, cycle, pageRenderSupport, symbols);
+            }
         }
 
         renderBody(writer, cycle);

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/Submit.jwc
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/Submit.jwc?view=diff&rev=544313&r1=544312&r2=544313
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/Submit.jwc
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/Submit.jwc
Mon Jun  4 15:26:02 2007
@@ -84,11 +84,8 @@
   </parameter>
   
   <parameter name="updateComponents" />
-  
   <parameter name="json" default-value="false" />
-  
   <parameter name="async" default-value="false" />
-  
   <parameter name="id" property="idParameter" default-value="id"/>
   
   <reserved-parameter name="name"/>

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/LinkSubmitTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/LinkSubmitTest.java?view=diff&rev=544313&r1=544312&r2=544313
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/LinkSubmitTest.java
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/LinkSubmitTest.java
Mon Jun  4 15:26:02 2007
@@ -18,24 +18,25 @@
 import org.apache.hivemind.Location;
 import org.apache.hivemind.Resource;
 import org.apache.tapestry.*;
+import org.apache.tapestry.engine.DirectServiceParameter;
+import org.apache.tapestry.engine.IEngineService;
+import org.apache.tapestry.engine.ILink;
 import org.apache.tapestry.valid.IValidationDelegate;
-import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.*;
 import org.testng.annotations.Test;
 
+import java.util.Arrays;
+import java.util.List;
 import java.util.Map;
 
 /**
- * Tests for {@link org.apache.tapestry.form.LinkSubmit}
- * 
- * @author Howard Lewis Ship
- * @since 4.0
+ * Tests for {@link org.apache.tapestry.form.LinkSubmit} 
  */
-@Test(sequential=true)
+@Test
 public class LinkSubmitTest extends BaseComponentTestCase
 {
     private class ScriptFixture implements IScript
     {
-
         public void execute(IRequestCycle cycle, IScriptProcessor processor, Map symbols)
         {
             assertNotNull(cycle);
@@ -74,9 +75,7 @@
                                             "id", "fred_id", "clientId", "fred_1", "submitType",
"submit");
         
         linkSubmit.addBody(newBody());
-
         trainGetSupport(cycle, support);
-        
         trainResponseBuilder(cycle, writer);
         
         replay();
@@ -107,6 +106,44 @@
         verify();
 
         assertBuffer("BODY");
+    }
+
+    public void test_Render_Submit_Bindings_True()
+    {
+        IMarkupWriter writer = newBufferWriter();
+        IRequestCycle cycle = newCycle();
+        IScript script = new ScriptFixture();
+        PageRenderSupport support = newPageRenderSupport();
+
+        IEngineService engine = newMock(IEngineService.class);
+        ILink link = newMock(ILink.class);
+        
+        IForm form = newForm();
+        List updates = Arrays.asList("comp1", "comp2");
+
+        LinkSubmit linkSubmit = newInstance(LinkSubmit.class,
+                                            "updateComponents", updates,
+                                            "form", form,
+                                            "name", "submitMe",
+                                            "clientId", "submitMe",
+                                            "submitType", FormConstants.SUBMIT_NORMAL,
+                                            "directService", engine,
+                                            "submitScript", script);
+        linkSubmit.addBody(newBody());
+
+        expect(engine.getLink(eq(true), isA(DirectServiceParameter.class))).andReturn(link);
+        expect(link.getURL()).andReturn("http://submit");
+
+        trainGetSupport(cycle, support);
+        trainResponseBuilder(cycle, writer);
+
+        replay();
+
+        linkSubmit.renderFormComponent(writer, cycle);
+
+        verify();
+
+        assertBuffer("<a href=\"#\" id=\"submitMe\">BODY</a>");
     }
 
     public void test_Prepare_Normal()

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/TestSubmit.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/TestSubmit.java?view=diff&rev=544313&r1=544312&r2=544313
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/TestSubmit.java
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/TestSubmit.java
Mon Jun  4 15:26:02 2007
@@ -14,25 +14,8 @@
 
 package org.apache.tapestry.form;
 
-import static org.easymock.EasyMock.aryEq;
-import static org.easymock.EasyMock.eq;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.isA;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
 import org.apache.hivemind.util.PropertyUtils;
-import org.apache.tapestry.IActionListener;
-import org.apache.tapestry.IBinding;
-import org.apache.tapestry.IForm;
-import org.apache.tapestry.IMarkupWriter;
-import org.apache.tapestry.IRequestCycle;
-import org.apache.tapestry.IScript;
-import org.apache.tapestry.PageRenderSupport;
+import org.apache.tapestry.*;
 import org.apache.tapestry.engine.DirectServiceParameter;
 import org.apache.tapestry.engine.IEngineService;
 import org.apache.tapestry.engine.ILink;
@@ -41,8 +24,11 @@
 import org.apache.tapestry.util.ScriptUtils;
 import org.apache.tapestry.valid.IValidationDelegate;
 import org.apache.tapestry.valid.ValidationConstants;
+import static org.easymock.EasyMock.*;
 import org.testng.annotations.Test;
 
+import java.util.*;
+
 /**
  * Tests for {@link org.apache.tapestry.form.Submit}.
  * 
@@ -377,11 +363,11 @@
         IEngineService engine = newEngineService();
         ILink link = newMock(ILink.class);
         
-        Submit submit = newInstance(Submit.class, 
-                new Object[] {"submitType", "cancel", 
-            "submitScript", script, "form", form, 
-            "async", true, "updateComponents", updates,
-            "directService", engine});
+        Submit submit = newInstance(Submit.class,
+                                    "submitType", "cancel",
+                                    "submitScript", script, "form", form,
+                                    "async", true, "updateComponents", updates,
+                                    "directService", engine);
         
         submit.setBinding("onClick", binding);
         
@@ -389,7 +375,6 @@
         IMarkupWriter writer = newWriter();
         
         expect(engine.getLink(eq(true), isA(DirectServiceParameter.class))).andReturn(link);
-        
         expect(link.getURL()).andReturn("/test/url");
         
         PageRenderSupport prs = newPageRenderSupport();



Mime
View raw message