You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by ds...@apache.org on 2005/10/13 21:22:28 UTC

svn commit: r320883 - in /jakarta/tapestry/trunk: framework/src/documentation/content/xdocs/tapestry/ComponentReference/Script.xml framework/src/documentation/resources/images/tapestry/ComponentReference/Script.png status.xml

Author: dsolis
Date: Thu Oct 13 12:22:15 2005
New Revision: 320883

URL: http://svn.apache.org/viewcvs?rev=320883&view=rev
Log:
Fix bug:TAPESTRY-482. Document Script component

Added:
    jakarta/tapestry/trunk/framework/src/documentation/resources/images/tapestry/ComponentReference/Script.png   (with props)
Modified:
    jakarta/tapestry/trunk/framework/src/documentation/content/xdocs/tapestry/ComponentReference/Script.xml
    jakarta/tapestry/trunk/status.xml

Modified: jakarta/tapestry/trunk/framework/src/documentation/content/xdocs/tapestry/ComponentReference/Script.xml
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/documentation/content/xdocs/tapestry/ComponentReference/Script.xml?rev=320883&r1=320882&r2=320883&view=diff
==============================================================================
--- jakarta/tapestry/trunk/framework/src/documentation/content/xdocs/tapestry/ComponentReference/Script.xml (original)
+++ jakarta/tapestry/trunk/framework/src/documentation/content/xdocs/tapestry/ComponentReference/Script.xml Thu Oct 13 12:22:15 2005
@@ -28,11 +28,15 @@
   
   <body>
 
-<p> <strong>THIS PAGE UNDER CONSTRUCTION</strong>
+<p>A component that accesses a script file and adds JavaScript functions and statements to the response page. The specified script file is read and parsed and substitutions are made before the final scripting code is inserted into the page. This allows the JavaScript to be tailored to the ids and names that are generated by Tapestry.
+</p>
+<p>Components within a Script's body may access the input and output parameters of the Script via the OGNL expression components.scriptId.symbols.name.
+</p>
+<p>Note a Body component is required when using the Script element. The Body component is used to write out the JavaScript after the HTML &lt;body&gt; section and attach any initialization code to the body's "onload" event handler.
 </p>
 
 <p>
-  <strong>See also:</strong> 
+  <strong>See also: &Body;</strong>
 </p>
 
 <section>
@@ -47,15 +51,37 @@
     <th>Default</th>
     <th>Description</th>
   </tr>
+    <tr>
+      <td>script</td>
+      <td>String</td>
+
+      <td>in</td>
+      <td>yes</td>
+      <td>&nbsp;</td>
+      <td>
+        The path of a resource (on the classpath) containing the script.
+      </td>
+    </tr>
+    <tr>
+      <td>symbols</td>
+      <td>java.util.Map</td>
+
+      <td>in</td>
+      <td>no</td>
+      <td>&nbsp;</td>
+      <td>
+         The base set of symbols to be provided to the &IScript;. To this is added (in a copy of the Map) any informal parameters.
+      </td>
+    </tr>
 
 	</table>
   
 <p>
-  Body: <strong>removed / allowed</strong>
+  Body: <strong>allowed</strong>
 </p>  
 
 <p>
-  Informal parameters: <strong>allowed  / forbidden</strong>
+  Informal parameters: <strong>allowed</strong>
 </p>
 
 <p>
@@ -66,6 +92,119 @@
 
 <section>
   <title>Examples</title>
+<p> See the &PropertySelection; example use of SelectSubmit script to submit a &Form; when a user selects a drop down list item.
+</p>
+<p>In this example a Script is used set the focus to the first text field of the login form. In the script file <![CDATA[ .. ]]> tags are used to wrap the JavaScript code to prevent '&lt;' and '&amp;&amp;' character XML parsing errors.
+</p>
+<p>Note Tapestry will not perform property substitutions in CDATA blocks when using the &lt;expression&gt; style syntax, instead use the ${expression} syntax.
+</p>
+    <figure src="&projectroot;/images/tapestry/ComponentReference/Script.png" alt="Script Screen Shot"/>
+    <p><strong>HTML Template</strong></p>
+    <source><![CDATA[
+<body jwcid="@Body">
+<span jwcid="@Script" script="/com/mycorp/scripts/FormFocus.script"/>
+<form jwcid="@Form" listener="ognl:listener.formSubmit">
+ <table cellpadding="4">
+   <tr><td>Username:</td><td><input jwcid="@TextField" value="ognl:visit.username" size="12"/></td>
+  </tr>
+   <tr><td>Password:</td><td><input jwcid="@TextField" value="ognl:visit.password" hidden="ognl:true" size="12"/></td>
+  </tr>
+  <tr align="right">
+   <td colspan="2"><input type="submit" value="Login"/></td>
+  </tr>
+ </table>
+</form>
+</body>
+    ]]></source>
+    <p><strong>Script File (FormFocus.script)</strong></p>
+    <source><![CDATA[
+<script>
+  <body>
+<![CDATA[
+function setFocus() {
+    if (document.forms[0]) {
+        for (i = 0; i < document.forms[0].elements.length; i++) {
+            if (document.forms[0].elements[i].type != "hidden" &&
+                document.forms[0].elements[i].disabled != true) {
+
+                document.forms[0].elements[i].focus();
+                return;
+            }
+        }
+    }
+}]]>
+]]&gt;
+<![CDATA[  </body>
+  <initialization>
+    setFocus();
+  </initialization>
+</script>
+        ]]></source>
+<p> This alternative FormFocus.script specifies the actual input field to give the focus to. The target input field is identified by an informal parameter named component. The script then uses ${expression} element name insertions to complete the JavaScript.
+</p>
+<p>Note when using this script, the target input field component must be declared before the script component in the HTML template, and within the Form block, so that the target field component can be resolved by the Script component.
+</p>
+    <p><strong>HTML Template</strong></p>
+    <source><![CDATA[
+<body jwcid="@Body">
+<form jwcid="@Form" listener="ognl:listener.formSubmit">
+ <table cellpadding=
+  "4">
+   <tr><td>Username:</td><td><input jwcid="usernameTextField@TextField" value="ognl:visit.username" size="12"/></td>
+  </tr>
+   <tr><td>Password:</td><td><input jwcid="@TextField" value="ognl:visit.password" hidden="ognl:true" size="12"/></td>
+  </tr>
+  <tr align="right">
+   <td colspan="2"><input type="submit" value="Login"/></td>
+  </tr>
+ </table>
+ <span jwcid="@Script" script="/com/mycorp/scripts/FormFocus.script" component="ognl:components.usernameTextField"/>
+</form>
+</body>
+    ]]></source>
+
+    <p><strong>Script File (FormFocus.script)</strong></p>
+    <source><![CDATA[
+<!--
+Selects the specified form input field on body load if the input type is not
+"hidden" and the input field is not disabled.
+
+Input symbols:
+  component: the component input field to give focus
+-->
+
+<input-symbol key="component" class="org.apache.tapestry.form.AbstractFormComponent" required="yes"/>
+
+<let key="formObject">
+	document.${component.form.name}
+</let>
+
+<let key="componentObject">
+	${formObject}.${component.name}
+</let>
+
+<script>
+
+<body>
+function setFocus() {
+    var inputField = ${componentObject.name};
+
+    if (inputField.type != "hidden") {
+        if (inputField.disabled != true) {
+            inputField.focus();
+        }
+    } else {
+         window.alert('InputFocus.script cannot set focus on a hidden field');
+    }
+}
+</body>
+
+<initialization>
+    setFocus();
+</initialization>
+
+</script>
+    ]]></source>
 
 </section>
 </body>

Added: jakarta/tapestry/trunk/framework/src/documentation/resources/images/tapestry/ComponentReference/Script.png
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/framework/src/documentation/resources/images/tapestry/ComponentReference/Script.png?rev=320883&view=auto
==============================================================================
Binary file - no diff available.

Propchange: jakarta/tapestry/trunk/framework/src/documentation/resources/images/tapestry/ComponentReference/Script.png
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Modified: jakarta/tapestry/trunk/status.xml
URL: http://svn.apache.org/viewcvs/jakarta/tapestry/trunk/status.xml?rev=320883&r1=320882&r2=320883&view=diff
==============================================================================
--- jakarta/tapestry/trunk/status.xml (original)
+++ jakarta/tapestry/trunk/status.xml Thu Oct 13 12:22:15 2005
@@ -57,6 +57,7 @@
       <action type="fix" dev="DS" fixes-bug="TAPESTRY-460, TAPESTRY-462, TAPESTRY-468" due-to="Warner Onstine">Document Delegator, ExceptionDisplay, Hidden components</action>
       <action type="fix" dev="DS" fixes-bug="TAPESTRY-472">Document LinkSubmit component</action>
       <action type="fix" dev="DS" fixes-bug="TAPESTRY-470">Document Image component</action>
+      <action type="fix" dev="DS" fixes-bug="TAPESTRY-482">Document Script component</action>
     </release>
     <release version="4.0-beta-10" date="Oct 8 2005">
       <action type="fix" dev="HLS" fixes-bug="TAPESTRY-344">Unimplemented abstract method check broken</action>



---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-dev-help@jakarta.apache.org