tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jkuhn...@apache.org
Subject svn commit: r565853 [2/2] - in /tapestry/tapestry4/trunk/tapestry-framework/src: java/org/apache/tapestry/ java/org/apache/tapestry/form/ java/org/apache/tapestry/script/ java/org/apache/tapestry/services/ java/org/apache/tapestry/services/impl/ java/o...
Date Tue, 14 Aug 2007 18:49:39 GMT
Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/PrototypeResponseBuilder.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/PrototypeResponseBuilder.java?view=diff&rev=565853&r1=565852&r2=565853
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/PrototypeResponseBuilder.java
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/services/impl/PrototypeResponseBuilder.java
Tue Aug 14 11:49:37 2007
@@ -20,7 +20,7 @@
 
 /**
  * Implementation of response builder for prototype client side library initiated XHR requests.
- * 
+ *
  */
 public class PrototypeResponseBuilder implements ResponseBuilder {
 
@@ -59,7 +59,7 @@
     {
         _cycle = cycle;
         _writer = writer;
-        
+
         if (parts != null)
             _parts.addAll(parts);
 
@@ -70,7 +70,7 @@
     /**
      * Creates a new response builder with the required services it needs
      * to render the response when {@link #renderResponse(IRequestCycle)} is called.
-     * 
+     *
      * @param cycle
      *          Associated request.
      * @param localeManager
@@ -85,10 +85,10 @@
      *          Javascript namespace value - used in portlets.
      */
     public PrototypeResponseBuilder(IRequestCycle cycle,
-            RequestLocaleManager localeManager,
-            MarkupWriterSource markupWriterSource,
-            WebResponse webResponse,
-            AssetFactory assetFactory, String namespace)
+                                    RequestLocaleManager localeManager,
+                                    MarkupWriterSource markupWriterSource,
+                                    WebResponse webResponse,
+                                    AssetFactory assetFactory, String namespace)
     {
         Defense.notNull(cycle, "cycle");
         Defense.notNull(assetFactory, "assetService");
@@ -117,7 +117,7 @@
      * {@inheritDoc}
      */
     public void renderResponse(IRequestCycle cycle)
-        throws IOException
+      throws IOException
     {
         _localeManager.persistLocale();
 
@@ -132,8 +132,8 @@
             contentType.setParameter(ENCODING_KEY, encoding);
         }
 
-        if (_writer == null) {
-
+        if (_writer == null)
+        {
             parseParameters(cycle);
 
             PrintWriter printWriter = _response.getPrintWriter(contentType);
@@ -157,7 +157,7 @@
     }
 
     public void flush()
-    throws IOException
+      throws IOException
     {
         _writer.flush();
     }
@@ -190,8 +190,8 @@
     public boolean isBodyScriptAllowed(IComponent target)
     {
         if (target != null
-                && IPage.class.isInstance(target)
-                || (IForm.class.isInstance(target)
+            && IPage.class.isInstance(target)
+            || (IForm.class.isInstance(target)
                 && ((IForm)target).isFormFieldUpdating()))
             return true;
 
@@ -204,8 +204,8 @@
     public boolean isExternalScriptAllowed(IComponent target)
     {
         if (target != null
-                && IPage.class.isInstance(target)
-                || (IForm.class.isInstance(target)
+            && IPage.class.isInstance(target)
+            || (IForm.class.isInstance(target)
                 && ((IForm)target).isFormFieldUpdating()))
             return true;
 
@@ -218,8 +218,8 @@
     public boolean isInitializationScriptAllowed(IComponent target)
     {
         if (target != null
-                && IPage.class.isInstance(target)
-                || (IForm.class.isInstance(target)
+            && IPage.class.isInstance(target)
+            || (IForm.class.isInstance(target)
                 && ((IForm)target).isFormFieldUpdating()))
             return true;
 
@@ -232,8 +232,8 @@
     public boolean isImageInitializationAllowed(IComponent target)
     {
         if (target != null
-                && IPage.class.isInstance(target)
-                || (IForm.class.isInstance(target)
+            && IPage.class.isInstance(target)
+            || (IForm.class.isInstance(target)
                 && ((IForm)target).isFormFieldUpdating()))
             return true;
 
@@ -312,6 +312,11 @@
         _prs.addInitializationScript(script);
     }
 
+    public void addScriptAfterInitialization(IComponent target, String script)
+    {
+        _prs.addScriptAfterInitialization(target, script);
+    }
+
     /**
      * {@inheritDoc}
      */
@@ -403,7 +408,7 @@
     {
         throw new UnsupportedOperationException("Can't return a status response with prototype
based requests.");
     }
-    
+
     /**
      * {@inheritDoc}
      */
@@ -411,7 +416,8 @@
     {
         // must be a valid writer already
 
-        if (NestedMarkupWriterImpl.class.isInstance(writer)) {
+        if (NestedMarkupWriterImpl.class.isInstance(writer))
+        {
             render.render(writer, cycle);
             return;
         }
@@ -440,11 +446,11 @@
     public IMarkupWriter getWriter(String id, String type)
     {
         Defense.notNull(id, "id can't be null");
-        
+
         IMarkupWriter w = (IMarkupWriter)_writers.get(id);
         if (w != null)
             return w;
-        
+
         IMarkupWriter nestedWriter = _writer.getNestedWriter();
         _writers.put(id, nestedWriter);
 
@@ -473,14 +479,14 @@
     {
         Iterator keys = _writers.keySet().iterator();
 
-        while (keys.hasNext()) {
-
+        while (keys.hasNext())
+        {
             String key = (String)keys.next();
             NestedMarkupWriter nw = (NestedMarkupWriter)_writers.get(key);
-            
+
             nw.close();
         }
-        
+
         _writer.flush();
     }
 
@@ -527,8 +533,8 @@
             return true;
 
         Iterator it = _cycle.renderStackIterator();
-        while (it.hasNext()) {
-
+        while (it.hasNext())
+        {
             IComponent comp = (IComponent)it.next();
             String compId = comp.getClientId();
 

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/util/PageRenderSupportImpl.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/util/PageRenderSupportImpl.java?view=diff&rev=565853&r1=565852&r2=565853
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/util/PageRenderSupportImpl.java
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/util/PageRenderSupportImpl.java
Tue Aug 14 11:49:37 2007
@@ -44,8 +44,13 @@
     private final ResponseBuilder _builder;
 
     // Lines that belong inside the onLoad event handler for the <body> tag.
+
     private StringBuffer _initializationScript;
 
+    // Used by addScriptAfterInitialization
+
+    private StringBuffer _postInitializationScript;
+
     // Any other scripting desired
 
     private StringBuffer _bodyScript;
@@ -202,6 +207,19 @@
         _initializationScript.append("\n").append(val);
     }
 
+    public void addScriptAfterInitialization(IComponent target, String script)
+    {
+        if (!_builder.isInitializationScriptAllowed(target))
+            return;
+
+        String strippedScript = stripDuplicateIncludes(script);
+
+        if (_postInitializationScript == null)
+            _postInitializationScript = new StringBuffer(strippedScript.length() + 1);
+
+        _postInitializationScript.append("\n").append(strippedScript);
+    }
+
     /**
      * Provides a mechanism to strip out duplicate dojo.require calls made in script
      * templates in order to reduce amount of redundant javascript written to client.
@@ -218,15 +236,18 @@
 
         String ret = input;
 
-        for (int i=0; i < lines.length; i++) {
+        for (int i=0; i < lines.length; i++)
+        {
             if (lines[i].indexOf("dojo.require") < 0)
                 continue;
 
             String line = StringUtils.stripToEmpty(lines[i]);
 
-            if (_requires.containsKey(line)) {
+            if (_requires.containsKey(line))
+            {
                 ret = StringUtils.replaceOnce(ret, line+";", "");
-            } else {
+            } else
+            {
                 _requires.put(line, "t");
             }
         }
@@ -287,6 +308,10 @@
      * </ul>
      *
      * @see #writeInitializationScript(IMarkupWriter)
+     * @param writer
+     *          The markup writer to use.
+     * @param cycle
+     *          The current request.
      */
 
     public void writeBodyScript(IMarkupWriter writer, IRequestCycle cycle)
@@ -301,15 +326,15 @@
 
         if (any(_imageInitializations))
         {
-            _builder.writeImageInitializations(writer, StringUtils.stripToEmpty(_imageInitializations.toString())
-              , _preloadName, cycle);
+            _builder.writeImageInitializations(writer,
+                                               StringUtils.stripToEmpty(_imageInitializations.toString()),
+                                               _preloadName,
+                                               cycle);
         }
 
         if (any(_bodyScript))
         {
-            _builder.writeBodyScript(writer, StringUtils.stripToEmpty(_bodyScript.toString())
-              ,
-                                     cycle);
+            _builder.writeBodyScript(writer, StringUtils.stripToEmpty(_bodyScript.toString()),
cycle);
         }
 
         _builder.endBodyScript(writer, cycle);
@@ -319,14 +344,27 @@
      * Writes any image initializations; this should be invoked at the end of the render,
after all
      * the related HTML will have already been streamed to the client and parsed by the web
browser.
      * Earlier versions of Tapestry uses a <code>window.onload</code> event handler.
+     *
+     * @param writer
+     *          The markup writer to use.
      */
 
     public void writeInitializationScript(IMarkupWriter writer)
     {
-        if (!any(_initializationScript))
+        if (!any(_initializationScript) && !any(_postInitializationScript))
             return;
 
-        _builder.writeInitializationScript(writer, StringUtils.stripToEmpty(_initializationScript.toString()));
+        String script = getContent(_initializationScript) + getContent(_postInitializationScript);
+
+        _builder.writeInitializationScript(writer, StringUtils.stripToEmpty(script));
+    }
+
+    public static String getContent(StringBuffer buffer)
+    {
+        if (buffer == null || buffer.length() < 1)
+            return "";
+        
+        return buffer.toString();
     }
 
     private boolean any(StringBuffer buffer)

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/version.properties
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/version.properties?view=diff&rev=565853&r1=565852&r2=565853
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/version.properties
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/version.properties
Tue Aug 14 11:49:37 2007
@@ -1 +1 @@
-project.version=4.1.2
+project.version=4.1.3

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/form.js
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/form.js?view=diff&rev=565853&r1=565852&r2=565853
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/form.js (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/form.js Tue Aug 14 11:49:37
2007
@@ -42,7 +42,9 @@
 		
 		var f=dojo.widget.byId(field);
 		if(f && !dj_undef("focus", f)){
-			f.focus();
+			if (dojo.html.isVisible(f)){
+				f.focus();
+			}
 			return;
 		} else {
 			f = dojo.byId(field);

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/FormSupportTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/FormSupportTest.java?view=diff&rev=565853&r1=565852&r2=565853
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/FormSupportTest.java
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/form/FormSupportTest.java
Tue Aug 14 11:49:37 2007
@@ -226,7 +226,8 @@
 
         trainGetFieldFocus(cycle, null);
 
-        support.addInitializationScript(form, "dojo.require(\"tapestry.form\");tapestry.form.focusField('wilma');");
+        support.addInitializationScript(form, "dojo.require(\"tapestry.form\");");
+        support.addScriptAfterInitialization(form, "tapestry.form.focusField('wilma');");
         cycle.setAttribute(FormSupportImpl.FIELD_FOCUS_ATTRIBUTE, Boolean.TRUE);
 
         replay();
@@ -1098,8 +1099,8 @@
 
         trainGetFieldFocus(cycle, null);
 
-        support.addInitializationScript(form, "dojo.require(\"tapestry.form\");tapestry.form.focusField('barney');");
-
+        support.addInitializationScript(form, "dojo.require(\"tapestry.form\");");
+        support.addScriptAfterInitialization(form, "tapestry.form.focusField('barney');");
         cycle.setAttribute(FormSupportImpl.FIELD_FOCUS_ATTRIBUTE, Boolean.TRUE);
 
         replay();

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/junit/script/MockScriptProcessor.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/junit/script/MockScriptProcessor.java?view=diff&rev=565853&r1=565852&r2=565853
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/junit/script/MockScriptProcessor.java
(original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/test/org/apache/tapestry/junit/script/MockScriptProcessor.java
Tue Aug 14 11:49:37 2007
@@ -14,17 +14,18 @@
 
 package org.apache.tapestry.junit.script;
 
-import java.util.ArrayList;
-import java.util.List;
-
 import org.apache.hivemind.Resource;
 import org.apache.tapestry.IComponent;
 import org.apache.tapestry.IScriptProcessor;
 import org.apache.tapestry.util.IdAllocator;
+import org.apache.tapestry.util.PageRenderSupportImpl;
+
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * Used by {@link org.apache.tapestry.junit.script.TestScript}.
- * 
+ *
  * @author Howard Lewis Ship
  * @since 3.0
  */
@@ -34,6 +35,8 @@
 
     private StringBuffer _initialization;
 
+    private StringBuffer _postInitialization;
+
     private List _externalScripts;
 
     private IdAllocator _idAllocator = new IdAllocator();
@@ -48,7 +51,7 @@
             _externalScripts.clear();
         _idAllocator.clear();
     }
-    
+
     public void addBodyScript(String script)
     {
         addBodyScript(null, script);
@@ -61,7 +64,7 @@
 
         _body.append(script);
     }
-    
+
     public String getBody()
     {
         if (_body == null)
@@ -82,20 +85,29 @@
 
         _initialization.append(script);
     }
-    
+
+    public void addScriptAfterInitialization(IComponent target, String script)
+    {
+        if (_postInitialization == null)
+            _postInitialization = new StringBuffer();
+
+        _postInitialization.append(script);
+    }
+
     public String getInitialization()
     {
-        if (_initialization == null)
+        if (_initialization == null && _postInitialization == null)
             return null;
 
-        return _initialization.toString();
+        return PageRenderSupportImpl.getContent(_initialization)
+               + PageRenderSupportImpl.getContent(_postInitialization);
     }
 
     public void addExternalScript(Resource scriptResource)
     {
         addExternalScript(null, scriptResource);
     }
-    
+
     /**
      * {@inheritDoc}
      */
@@ -124,7 +136,7 @@
     {
         if (_externalScripts == null)
             _externalScripts = new ArrayList();
-        
+
         _externalScripts.add(scriptResource);
     }
 



Mime
View raw message