tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jkuhn...@apache.org
Subject svn commit: r481667 - in /tapestry/tapestry4/trunk: tapestry-examples/Workbench/src/context/WEB-INF/ tapestry-examples/Workbench/src/java/org/apache/tapestry/workbench/chart/ tapestry-framework/src/descriptor/META-INF/ tapestry-framework/src/java/org/a...
Date Sat, 02 Dec 2006 23:19:24 GMT
Author: jkuhnert
Date: Sat Dec  2 15:19:22 2006
New Revision: 481667

URL: http://svn.apache.org/viewvc?view=rev&rev=481667
Log:
Removed DirectLinkWorker. Was a brain dead idea. DefaultLinkRenderer now handles connecting
async events 
up if the right parameters exist. Also selectively renders a more efficient onClick attribute
if none currently 
exist, else reverts to more verbose scripted version.

Added:
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/link/DirectLink.script
      - copied unchanged from r481565, tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/link/DirectLinkWorker.script
Removed:
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/link/DirectLinkWorker.java
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/link/DirectLinkWorker.script
    tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/link/DirectLinkWorkerTest.java
Modified:
    tapestry/tapestry4/trunk/tapestry-examples/Workbench/src/context/WEB-INF/hivemodule.xml
    tapestry/tapestry4/trunk/tapestry-examples/Workbench/src/java/org/apache/tapestry/workbench/chart/ChartService.java
    tapestry/tapestry4/trunk/tapestry-framework/src/descriptor/META-INF/tapestry.render.xml
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/link/DefaultLinkRenderer.java
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/link/DirectLink.java
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/link/DirectLink.jwc
    tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/core.js

Modified: tapestry/tapestry4/trunk/tapestry-examples/Workbench/src/context/WEB-INF/hivemodule.xml
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-examples/Workbench/src/context/WEB-INF/hivemodule.xml?view=diff&rev=481667&r1=481666&r2=481667
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-examples/Workbench/src/context/WEB-INF/hivemodule.xml
(original)
+++ tapestry/tapestry4/trunk/tapestry-examples/Workbench/src/context/WEB-INF/hivemodule.xml
Sat Dec  2 15:19:22 2006
@@ -40,7 +40,7 @@
     <invoke-factory>
       <construct class="chart.ChartService">
         <set-object property="exceptionReporter" value="infrastructure:requestExceptionReporter"/>
-        <set-object property="response" value="infrastructure:response"/>
+        <set-service property="response" service-id="tapestry.globals.HttpServletResponse"/>
         <set-object property="linkFactory" value="infrastructure:linkFactory"/>
       </construct>
     </invoke-factory>

Modified: tapestry/tapestry4/trunk/tapestry-examples/Workbench/src/java/org/apache/tapestry/workbench/chart/ChartService.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-examples/Workbench/src/java/org/apache/tapestry/workbench/chart/ChartService.java?view=diff&rev=481667&r1=481666&r2=481667
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-examples/Workbench/src/java/org/apache/tapestry/workbench/chart/ChartService.java
(original)
+++ tapestry/tapestry4/trunk/tapestry-examples/Workbench/src/java/org/apache/tapestry/workbench/chart/ChartService.java
Sat Dec  2 15:19:22 2006
@@ -15,10 +15,11 @@
 package org.apache.tapestry.workbench.chart;
 
 import java.io.IOException;
-import java.io.OutputStream;
 import java.util.HashMap;
 import java.util.Map;
 
+import javax.servlet.http.HttpServletResponse;
+
 import org.apache.hivemind.util.Defense;
 import org.apache.tapestry.IComponent;
 import org.apache.tapestry.IPage;
@@ -28,8 +29,6 @@
 import org.apache.tapestry.error.RequestExceptionReporter;
 import org.apache.tapestry.services.LinkFactory;
 import org.apache.tapestry.services.ServiceConstants;
-import org.apache.tapestry.util.ContentType;
-import org.apache.tapestry.web.WebResponse;
 import org.jCharts.Chart;
 import org.jCharts.encoders.JPEGEncoder13;
 
@@ -53,7 +52,7 @@
     private LinkFactory _linkFactory;
 
     /** @since 4.0 */
-    private WebResponse _response;
+    private HttpServletResponse _response;
 
     public ILink getLink(boolean post, Object parameter)
     {
@@ -81,19 +80,10 @@
         try
         {
             IChartProvider provider = (IChartProvider) component;
-
+            
             Chart chart = provider.getChart();
-
-            OutputStream output = _response.getOutputStream(new ContentType("image/jpeg"));
-
-            // I've seen a few bits of wierdness (including a JVM crash) inside this code.
-            // Hopefully, its a multi-threading problem that can be resolved
-            // by synchronizing.
-
-            synchronized (this)
-            {
-                JPEGEncoder13.encode(chart, 1.0f, output);
-            }
+            
+            JPEGEncoder13.encode(chart, 1.0f, _response);
         }
         catch (ClassCastException ex)
         {
@@ -130,7 +120,7 @@
     }
 
     /** @since 4.0 */
-    public void setResponse(WebResponse response)
+    public void setResponse(HttpServletResponse response)
     {
         _response = response;
     }

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/descriptor/META-INF/tapestry.render.xml
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/descriptor/META-INF/tapestry.render.xml?view=diff&rev=481667&r1=481666&r2=481667
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/descriptor/META-INF/tapestry.render.xml
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/descriptor/META-INF/tapestry.render.xml
Sat Dec  2 15:19:22 2006
@@ -55,25 +55,8 @@
   
   </service-point>
   
-  <service-point id="DirectLinkWorker" 
-                interface="org.apache.tapestry.services.ComponentRenderWorker">
-    
-    Wires the optional parameters updateComponents/async/json shared by all IDirect components
-    to client side javascript IO events if specified.
-    
-    <invoke-factory model="threaded">
-      <construct class="org.apache.tapestry.link.DirectLinkWorker"
-                 initialize-method="initialize" >
-        <set property="script" value="/org/apache/tapestry/link/DirectLinkWorker.script"
/>
-        <set-service property="scriptSource" service-id="tapestry.script.ScriptSource"/>
-      </construct>
-    </invoke-factory>
-  
-  </service-point>
-  
   <contribution configuration-id="ComponentRenderWorkers">
     <command id="component-event-connection" object="service:ComponentEventConnectionWorker"
/>
-    <command id="direct-link-worker" object="service:DirectLinkWorker" />
   </contribution>
   
 </module>

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/link/DefaultLinkRenderer.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/link/DefaultLinkRenderer.java?view=diff&rev=481667&r1=481666&r2=481667
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/link/DefaultLinkRenderer.java
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/link/DefaultLinkRenderer.java
Sat Dec  2 15:19:22 2006
@@ -14,13 +14,19 @@
 
 package org.apache.tapestry.link;
 
+import java.util.HashMap;
+import java.util.Map;
+
 import org.apache.hivemind.ApplicationRuntimeException;
 import org.apache.hivemind.HiveMind;
 import org.apache.tapestry.IMarkupWriter;
 import org.apache.tapestry.IRequestCycle;
+import org.apache.tapestry.PageRenderSupport;
 import org.apache.tapestry.Tapestry;
+import org.apache.tapestry.TapestryUtils;
 import org.apache.tapestry.components.ILinkComponent;
 import org.apache.tapestry.engine.ILink;
+import org.apache.tapestry.util.ScriptUtils;
 
 /**
  * Default implementation of {@link org.apache.tapestry.link.ILinkRenderer},
@@ -74,6 +80,12 @@
             if (HiveMind.isNonBlank(target))
                 writer.attribute(getTargetAttribute(), target);
             
+            if (DirectLink.class.isInstance(linkComponent)) {
+                DirectLink direct = (DirectLink)linkComponent;
+                
+                renderAsyncParams(writer, cycle, direct);
+            }
+            
             beforeBodyRender(writer, cycle, linkComponent);
             
             // Allow the wrapped components a chance to render.
@@ -150,6 +162,52 @@
     {
     }
 
+    /**
+     * For {@link DirectLink} components only, manages writing out event handlers for link
+     * if any of the dynamic (async/json/etc) parameters are set on the component.
+     * 
+     * <p>
+     *  Will try to write the logic into the <code>onClick</code> attribute of
the link 
+     *  if not bound, otherwise it will render it using the {@link DirectLink#getScript()}
script.
+     * </p>
+     * 
+     * @param writer
+     *          The writer to render attributes into.
+     * @param cycle
+     *          The current request cycle.
+     * @param link
+     *          The component link being rendered for.
+     */
+    protected void renderAsyncParams(IMarkupWriter writer, IRequestCycle cycle, DirectLink
link)
+    {
+        if (!link.isAsync() && !link.isJson() 
+                && (link.getUpdateComponents() == null 
+                || link.getUpdateComponents().size() <= 0))
+            return;
+        
+        if (!link.isParameterBound("onclick") && !link.isParameterBound("onClick"))
{
+            writer.attribute("onclick", 
+                    "return tapestry.linkOnClick(this.href,'" + link.getClientId() + "',
" 
+                    + link.isJson() + ")");
+            return;
+        }
+        
+        PageRenderSupport prs = TapestryUtils.getPageRenderSupport(cycle, link);
+        
+        if (prs == null)
+            return;
+        
+        Map parms = new HashMap();
+        
+        parms.put("component", link);
+        parms.put("json", Boolean.valueOf(link.isJson()));
+        parms.put("key", ScriptUtils.functionHash("onclick" + link.hashCode()));
+        
+        // execute script template
+        
+        link.getScript().execute(link, cycle, prs, parms);
+    }
+    
     /** @since 3.0 * */
 
     protected String getElement()

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/link/DirectLink.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/link/DirectLink.java?view=diff&rev=481667&r1=481666&r2=481667
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/link/DirectLink.java
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/link/DirectLink.java
Sat Dec  2 15:19:22 2006
@@ -19,6 +19,7 @@
 import org.apache.tapestry.IActionListener;
 import org.apache.tapestry.IDirect;
 import org.apache.tapestry.IRequestCycle;
+import org.apache.tapestry.IScript;
 import org.apache.tapestry.Tapestry;
 import org.apache.tapestry.engine.DirectServiceParameter;
 import org.apache.tapestry.engine.IEngineService;
@@ -123,4 +124,10 @@
      * @since 4.1
      */
     public abstract IEngineService getEngine();
+    
+    /**
+     * Injected.
+     * @return The script to process asynchronous connection hookups.
+     */
+    public abstract IScript getScript();
 }

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/link/DirectLink.jwc
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/link/DirectLink.jwc?view=diff&rev=481667&r1=481666&r2=481667
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/link/DirectLink.jwc
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/link/DirectLink.jwc
Sat Dec  2 15:19:22 2006
@@ -69,6 +69,8 @@
   
   <parameter name="async" default-value="false" />
   
+  <inject property="script" type="script" object="DirectLink.script"/>
+  
   <inject property="listenerInvoker" object="infrastructure:listenerInvoker"/>
   <inject object="service:tapestry.services.Direct" property="engine"/>
   

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/core.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/core.js?view=diff&rev=481667&r1=481666&r2=481667
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/core.js (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/core.js Sat Dec  2 15:19:22
2006
@@ -344,6 +344,14 @@
 		if (!dj_undef(funcName, tapestry)){
         	dojo.event.disconnect(target, event, tapestry, funcName);
         }
+	},
+	
+	linkOnClick:function(url, id, isJson){
+		var content={beventname:"onClick"};
+		content["beventtarget.id"]=id;
+		
+		tapestry.bind(url, content, isJson);
+		return false;
 	}
 }
 



Mime
View raw message