Author: hlship
Date: Wed May 11 02:02:47 2011
New Revision: 1101725
URL: http://svn.apache.org/viewvc?rev=1101725&view=rev
Log:
TAP5-1521: JavaScriptSupport.addInitializerCall() should support JSONArray of
function parameters, as RenderSupport does
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/RenderSupportImpl.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/JavaScriptSupportImpl.java
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/JavaScriptSupport.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/RenderSupportImplTest.java
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ajax/JavaScriptSupportImplTest.java
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/RenderSupportImpl.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/RenderSupportImpl.java?rev=1101725&r1=1101724&r2=1101725&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/RenderSupportImpl.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/RenderSupportImpl.java
Wed May 11 02:02:47 2011
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007, 2008, 2009, 2010 The Apache Software Foundation
+// Copyright 2006, 2007, 2008, 2009, 2010, 2011 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.
@@ -107,7 +107,7 @@ public class RenderSupportImpl implement
public void addInit(String functionName, JSONArray parameterList)
{
- addInitFunctionInvocation(functionName, parameterList);
+ javascriptSupport.addInitializerCall(functionName, parameterList);
}
public void addInit(String functionName, JSONObject parameter)
@@ -132,23 +132,6 @@ public class RenderSupportImpl implement
javascriptSupport.autofocus(priority, fieldId);
}
- /**
- * For the few existing places that use the old variations of addInit(),
passing a list of
- * strings or a JSONArray, the end result is a bit inefficient. We end up
generating lots
- * of calls to Tapestry.init, with no attempt to aggregate them. Most of
the time, the init
- * occurs with a JSONObject (the "spec") and is handled by {@link
JavaScriptSupport}.
- */
- private void addInitFunctionInvocation(String functionName, Object
parameters)
- {
- assert InternalUtils.isNonBlank(functionName);
- assert parameters != null;
-
- JSONArray list = new JSONArray().put(parameters);
- JSONObject wrapper = new JSONObject().put(functionName, list);
-
- addScript("Tapestry.init(%s);", wrapper);
- }
-
public void addStylesheetLink(Asset stylesheet, String media)
{
javascriptSupport.importStylesheet(new StylesheetLink(stylesheet, new
StylesheetOptions(media)));
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/JavaScriptSupportImpl.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/JavaScriptSupportImpl.java?rev=1101725&r1=1101724&r2=1101725&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/JavaScriptSupportImpl.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/ajax/JavaScriptSupportImpl.java
Wed May 11 02:02:47 2011
@@ -1,4 +1,4 @@
-// Copyright 2010 The Apache Software Foundation
+// Copyright 2010, 2011 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.
@@ -145,6 +145,16 @@ public class JavaScriptSupportImpl imple
storeInitializerCall(priority, functionName, parameter);
}
+ public void addInitializerCall(String functionName, JSONArray parameter)
+ {
+ storeInitializerCall(InitializationPriority.NORMAL, functionName,
parameter);
+ }
+
+ public void addInitializerCall(InitializationPriority priority, String
functionName, JSONArray parameter)
+ {
+ storeInitializerCall(priority, functionName, parameter);
+ }
+
private void storeInitializerCall(InitializationPriority priority, String
functionName, Object parameter)
{
assert priority != null;
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/JavaScriptSupport.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/JavaScriptSupport.java?rev=1101725&r1=1101724&r2=1101725&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/JavaScriptSupport.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/services/javascript/JavaScriptSupport.java
Wed May 11 02:02:47 2011
@@ -20,6 +20,7 @@ import org.apache.tapestry5.FieldFocusPr
import org.apache.tapestry5.RenderSupport;
import org.apache.tapestry5.SymbolConstants;
import org.apache.tapestry5.annotations.Environmental;
+import org.apache.tapestry5.json.JSONArray;
import org.apache.tapestry5.json.JSONObject;
import org.apache.tapestry5.services.EnvironmentalShadowBuilder;
@@ -102,6 +103,32 @@ public interface JavaScriptSupport
/**
* Adds a call to a client-side function inside the Tapestry.Initializer
namespace. Calls to this
* method are aggregated into a call to the Tapestry.init() function.
Initialization occurs at
+ * {@link InitializationPriority#NORMAL} priority.
+ *
+ * @param functionName
+ * name of client-side function (within Tapestry.Initializer
namespace) to execute
+ * @param parameter
+ * array of parameters to pass to the client-side function
+ * @since 5.3.0
+ */
+ void addInitializerCall(String functionName, JSONArray parameter);
+
+ /**
+ * Adds a call to a client-side function inside the Tapestry.Initializer
namespace. Calls to this
+ * method are aggregated into a call to the Tapestry.init() function.
Initialization occurs at
+ * {@link InitializationPriority#NORMAL} priority.
+ *
+ * @param functionName
+ * name of client-side function (within Tapestry.Initializer
namespace) to execute
+ * @param parameter
+ * array of parameters to pass to the client-side function
+ * @since 5.3.0
+ */
+ void addInitializerCall(InitializationPriority priority, String
functionName, JSONArray parameter);
+
+ /**
+ * Adds a call to a client-side function inside the Tapestry.Initializer
namespace. Calls to this
+ * method are aggregated into a call to the Tapestry.init() function.
Initialization occurs at
* the specified priority.
*
* @param priority
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/RenderSupportImplTest.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/RenderSupportImplTest.java?rev=1101725&r1=1101724&r2=1101725&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/RenderSupportImplTest.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/RenderSupportImplTest.java
Wed May 11 02:02:47 2011
@@ -1,4 +1,4 @@
-// Copyright 2007, 2008, 2009 The Apache Software Foundation
+// Copyright 2007, 2008, 2009, 2011 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.
@@ -146,9 +146,9 @@ public class RenderSupportImplTest exten
{
JavaScriptSupport js = mockJavaScriptSupport();
- JSONObject spec = new JSONObject().put("foo", new JSONArray().put(new
JSONArray("fred", "barney")));
+ JSONArray array = new JSONArray("fred", "barney");
- js.addScript("Tapestry.init(%s);", spec);
+ js.addInitializerCall("foo", array);
replay();
Modified:
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ajax/JavaScriptSupportImplTest.java
URL:
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ajax/JavaScriptSupportImplTest.java?rev=1101725&r1=1101724&r2=1101725&view=diff
==============================================================================
---
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ajax/JavaScriptSupportImplTest.java
(original)
+++
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/ajax/JavaScriptSupportImplTest.java
Wed May 11 02:02:47 2011
@@ -402,7 +402,6 @@ public class JavaScriptSupportImplTest e
@Test
public void init_with_string()
{
-
DocumentLinker linker = mockDocumentLinker();
JavaScriptStackSource stackSource = mockJavaScriptStackSource();
JavaScriptStackPathConstructor pathConstructor =
mockJavaScriptStackPathConstructor();
@@ -425,6 +424,33 @@ public class JavaScriptSupportImplTest e
}
@Test
+ public void init_with_array()
+ {
+ DocumentLinker linker = mockDocumentLinker();
+ JavaScriptStackSource stackSource = mockJavaScriptStackSource();
+ JavaScriptStackPathConstructor pathConstructor =
mockJavaScriptStackPathConstructor();
+ trainForEmptyCoreStack(linker, stackSource, pathConstructor);
+
+ JSONArray chuck = new JSONArray("chuck", "yeager");
+ JSONArray buzz = new JSONArray("buzz", "aldrin");
+
+ JSONObject aggregated = new JSONObject().put("setup", new
JSONArray(chuck, buzz));
+
+ linker.setInitialization(InitializationPriority.IMMEDIATE, aggregated);
+
+ replay();
+
+ JavaScriptSupportImpl jss = new JavaScriptSupportImpl(linker,
stackSource, pathConstructor);
+
+ jss.addInitializerCall(InitializationPriority.IMMEDIATE, "setup",
chuck);
+ jss.addInitializerCall(InitializationPriority.IMMEDIATE, "setup",
buzz);
+
+ jss.commit();
+
+ verify();
+ }
+
+ @Test
public void default_for_init_string_is_normal_priority()
{
DocumentLinker linker = mockDocumentLinker();
@@ -448,6 +474,31 @@ public class JavaScriptSupportImplTest e
}
@Test
+ public void default_for_init_array_is_normal_priority()
+ {
+ DocumentLinker linker = mockDocumentLinker();
+ JavaScriptStackSource stackSource = mockJavaScriptStackSource();
+ JavaScriptStackPathConstructor pathConstructor =
mockJavaScriptStackPathConstructor();
+ trainForEmptyCoreStack(linker, stackSource, pathConstructor);
+
+ JSONArray chuck = new JSONArray("chuck", "yeager");
+
+ JSONObject aggregated = new JSONObject().put("setup", new
JSONArray(chuck));
+
+ linker.setInitialization(InitializationPriority.NORMAL, aggregated);
+
+ replay();
+
+ JavaScriptSupportImpl jss = new JavaScriptSupportImpl(linker,
stackSource, pathConstructor);
+
+ jss.addInitializerCall("setup", chuck);
+
+ jss.commit();
+
+ verify();
+ }
+
+ @Test
public void import_stylesheet_as_asset()
{
DocumentLinker linker = mockDocumentLinker();