You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2003/04/30 23:17:09 UTC
cvs commit: jakarta-tapestry/junit/mock-scripts TestLibrary.xml
hlship 2003/04/30 14:17:09
Modified: framework/src/org/apache/tapestry/html Body.java
web new.html
junit/mock-scripts TestLibrary.xml
Log:
[ 19490 ] Body Component renders invalid markup
Revision Changes Path
1.5 +55 -45 jakarta-tapestry/framework/src/org/apache/tapestry/html/Body.java
Index: Body.java
===================================================================
RCS file: /home/cvs/jakarta-tapestry/framework/src/org/apache/tapestry/html/Body.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- Body.java 25 Apr 2003 01:18:33 -0000 1.4
+++ Body.java 30 Apr 2003 21:17:09 -0000 1.5
@@ -55,10 +55,10 @@
package org.apache.tapestry.html;
+import java.util.ArrayList;
import java.util.HashMap;
-import java.util.HashSet;
+import java.util.List;
import java.util.Map;
-import java.util.Set;
import org.apache.tapestry.AbstractComponent;
import org.apache.tapestry.ApplicationRuntimeException;
@@ -73,7 +73,7 @@
/**
* The body of a Tapestry page. This is used since it allows components on the
- * page access to an initialization script (that is written the start, just before
+ * page access to an initialization script (that is written the start, just inside
* the <body> tag). This is currently used by {@link Rollover} and {@link Script}
* components.
*
@@ -110,13 +110,13 @@
private Map _imageMap;
/**
- * Set of included scripts. Values are Strings.
+ * List of included scripts. Values are Strings.
*
* @since 1.0.5
*
**/
- private Set _externalScripts;
+ private List _externalScripts;
private IdAllocator _idAllocator;
@@ -231,7 +231,7 @@
public void addExternalScript(IResourceLocation scriptLocation)
{
if (_externalScripts == null)
- _externalScripts = new HashSet();
+ _externalScripts = new ArrayList();
if (_externalScripts.contains(scriptLocation))
return;
@@ -243,24 +243,41 @@
Tapestry.getString("Body.include-classpath-script-only", scriptLocation),
this);
- // This is still very awkward! Should move the code inside PrivateAsset somewhere
- // else, so that an asset does not have to be created to to build the URL.
- PrivateAsset asset = new PrivateAsset((ClasspathResourceLocation) scriptLocation, null);
- String url = asset.buildURL(getPage().getRequestCycle());
-
- _outerWriter.begin("script");
- _outerWriter.attribute("language", "JavaScript");
- _outerWriter.attribute("type", "text/javascript");
- _outerWriter.attribute("src", url);
- _outerWriter.end();
- _outerWriter.println();
-
// Record the URL so we don't include it twice.
_externalScripts.add(scriptLocation);
}
/**
+ * Writes <script> elements for all the external scripts.
+ */
+ private void writeExternalScripts(IMarkupWriter writer)
+ {
+ int count = Tapestry.size(_externalScripts);
+ for (int i = 0; i < count; i++)
+ {
+ ClasspathResourceLocation scriptLocation =
+ (ClasspathResourceLocation) _externalScripts.get(i);
+
+ // This is still very awkward! Should move the code inside PrivateAsset somewhere
+ // else, so that an asset does not have to be created to to build the URL.
+ PrivateAsset asset = new PrivateAsset(scriptLocation, null);
+ String url = asset.buildURL(getPage().getRequestCycle());
+
+ // Note: important to use begin(), not beginEmpty(), because browser don't
+ // interpret <script .../> properly.
+
+ writer.begin("script");
+ writer.attribute("language", "JavaScript");
+ writer.attribute("type", "text/javascript");
+ writer.attribute("src", url);
+ writer.end();
+ writer.println();
+ }
+
+ }
+
+ /**
* Retrieves the <code>Body</code> that was stored into the
* request cycle. This allows components wrapped by the
* <code>Body</code> to locate it and access the services it
@@ -275,9 +292,6 @@
protected void renderComponent(IMarkupWriter writer, IRequestCycle cycle)
{
- IMarkupWriter nested;
- String onLoadName;
-
if (cycle.getAttribute(ATTRIBUTE_NAME) != null)
throw new ApplicationRuntimeException(Tapestry.getString("Body.may-not-nest"), this);
@@ -285,23 +299,21 @@
_outerWriter = writer;
- nested = writer.getNestedWriter();
+ IMarkupWriter nested = writer.getNestedWriter();
renderBody(nested, cycle);
- // Write the script (i.e., just before the <body> tag).
- // If an onLoad event handler was needed, its name is
- // returned.
-
- onLoadName = writeScript();
-
// Start the body tag.
writer.println();
writer.begin(getElement());
renderInformalParameters(writer, cycle);
- if (onLoadName != null)
- writer.attribute("onLoad", "javascript:" + onLoadName + "();");
+ writer.println();
+
+ // Write the page's scripting. This is included scripts
+ // and dynamic JavaScript, including initialization.
+
+ writeScript();
// Close the nested writer, which dumps its buffered content
// into its parent.
@@ -312,10 +324,10 @@
}
- protected void cleanupAfterRender(IRequestCycle cycle)
+ protected void cleanupAfterRender(IRequestCycle cycle)
{
- super.cleanupAfterRender(cycle);
-
+ super.cleanupAfterRender(cycle);
+
if (_idAllocator != null)
_idAllocator.clear();
@@ -335,6 +347,7 @@
_bodyScript.setLength(0);
_outerWriter = null;
+ _outerWriter = null;
}
/**
@@ -345,18 +358,20 @@
* <li>Any initializations
* </ul>
*
- * <p>The script is written just before the <body> tag.
+ * <p>The script is written into a nested markup writer.
*
* <p>If there are any other initializations
* (see {@link #addOtherInitialization(String)}),
- * then a function to execute them is created, and its name
- * is returned.
+ * then a function to execute them is created.
**/
- private String writeScript()
+ private void writeScript()
{
+ if (!Tapestry.isEmpty(_externalScripts))
+ writeExternalScripts(_outerWriter);
+
if (!(any(_initializationScript) || any(_bodyScript) || any(_imageInitializations)))
- return null;
+ return;
_outerWriter.begin("script");
_outerWriter.attribute("language", "JavaScript");
@@ -377,13 +392,10 @@
_outerWriter.printRaw(_bodyScript.toString());
}
- String result = null;
-
if (any(_initializationScript))
{
- result = "tapestry_onLoad";
- _outerWriter.printRaw("\n\n" + "function " + result + "()\n" + "{\n");
+ _outerWriter.printRaw("\n\n" + "window.onload = function ()\n" + "{\n");
_outerWriter.printRaw(_initializationScript.toString());
@@ -392,8 +404,6 @@
_outerWriter.printRaw("\n\n// -->");
_outerWriter.end();
-
- return result;
}
private boolean any(StringBuffer buffer)
1.163 +4 -2 jakarta-tapestry/web/new.html
Index: new.html
===================================================================
RCS file: /home/cvs/jakarta-tapestry/web/new.html,v
retrieving revision 1.162
retrieving revision 1.163
diff -u -r1.162 -r1.163
--- new.html 25 Apr 2003 23:18:27 -0000 1.162
+++ new.html 30 Apr 2003 21:17:09 -0000 1.163
@@ -43,6 +43,7 @@
</li>
<li>Integrated Per Norrman's vastly improved <a href="doc/ComponentReference/DatePicker.html">DatePicker</a> component</li>
<li>Changed the <code>service()</code> method on <a href="doc/api/org/apache/tapestry/engine/IEngineService.html">IEngineService</a> to return void, not boolean.</li>
+<li>Changes the <a href="doc/ComponentReference/Body.html">Body</a> component to render <script> tags just inside the <body> tag, not just before it.</li>
</ul>
<pre>
@@ -55,7 +56,8 @@
[ 19153 ] Easier way to override validation messages
[ 19263 ] Change error message for null parameter
[ 18880 ] DatePicker broken under Mozilla
-[ 19340 ] exception does not give class information
+[ 19340 ] exception does not give class information
+[ 19490 ] Body Component renders invalid markup
</pre>
<h3>Release 2.4-alpha-5</h3>
1.5 +3 -3 jakarta-tapestry/junit/mock-scripts/TestLibrary.xml
Index: TestLibrary.xml
===================================================================
RCS file: /home/cvs/jakarta-tapestry/junit/mock-scripts/TestLibrary.xml,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- TestLibrary.xml 20 Apr 2003 19:10:04 -0000 1.4
+++ TestLibrary.xml 30 Apr 2003 21:17:09 -0000 1.5
@@ -36,12 +36,12 @@
<match>/title</match>
<match>link</match>
<match>/head</match>
+ <match>body</match>
<match>script</match>
<match>/script</match>
<match>script</match>
<match>/script</match>
- <match>body</match>
-
+
<!-- Generated by the ServiceLink -->
<match>a</match>