The Script component is one of the more common ways to add scripting to a Tapestry page.
The component has a single required parameter, script that is the path to a Script document within the classpath. The optional symbols parameter allows a Map to be specified as the base set of symbols, to which are added any informal parameters.
A handful of scripts are included with the framework. The following script is used by the Tapestry Inspector to force a Form to submit when a PropertySelection changes value.
Figure 12.11. SelectSubmit.script
![]() | The property path makes it easy to find the Form containing the PropertySelection component. Part of the necessity for this script is that form and form element names are assigned by Tapestry. |
![]() | Here, the path refers to how to identify the HTML element in the browser's DOM. |
![]() | The function name is used twice; to define the function and to setup the event handler. Note how the name incorporates the unique form name and element name, this ensures that any number of PropertySelection components, inside any number of Forms can use this script without concern for naming conflicts. |
Using the script simply involves declaring it in the component specification and configuring its input parameters. It must also be in the HTML template, before the closing </jwc> tag of the Form component.