Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: cleaning up old wiki formatting

...

Tapestry provides several ways to add a link to a JavaScript library within your page or component. Although you can use direct <script type="text/javascript" src="xxx.js"></script> approach, you should only use it for JavaScript that resides outside of your application. For JavaScript within your app, Tapestry provides much better ways to do the same thing. Most users choose the simplest, the @Import annotation approach. Wiki Markup

{float:right|background=#eee|padding=0 1em} 
*JumpStart Demo:* 
[JavaScript|http://jumpstart.doublenegative.com.au/jumpstart/examples/javascript/javascript] 
{float}

Approach 1: @Import

Div
stylefloat: right; max-width: 30%
Panel
borderColor#eee
titleBGColor#eee
titleJumpStart Demo

 JavaScript

Approach 1: @Import

Use the @Import annotation Use the @Import annotation (or @IncludeJavaScriptLibrary in Tapestry 5.0 and 5.1) to include links to JavaScript (and CSS) files in your page or component. Tapestry ensures that each such file is only referenced once in your page.

...

The setupRender method (the name is specifically linked to a render phase) is the correct place to inform the JavaScriptSupport (or RenderSupport) service that the library is needed.

Div
style

...

max-width: 30%; float: right;
Panel
borderColor#eee
titleBGColor#eee
titleJumpStart Demo

 Reusable JavaScript

The addScript method

The addScript method is used when you need to add some JavaScript code directly to the page. This will be inserted at the bottom of the document, and will only be executed when the document has finished loading on the client (i.e., from the window.onload event handler).

...

Built-in Libraries

...

Div
style
float: right

...

; max-width: 30%
Panel
borderColor#eee
titleBGColor#eee
titleAlternatives to Prototype

Tapestry 5.4 includes the ability to switch between Prototype and JQuery. For Tapestry 5.3 and earlier, you also have some options::

 

Tapestry 5.4 and earlier come =30%|background=#eee} {color:green}*Alternatives to Prototype*{color} Tapestry also works well with other JavaScript libraries, such as JQuery and ExtJS: * *[Tapestry5-Jquery module|https://github.com/got5/tapestry5-jquery]* -- Using JQuery _instead of_ Prototype * [Tapestry5HowToIntegrateJQuery|http://wiki.apache.org/tapestry/Tapestry5HowToIntegrateJQuery] -- Using JQuery _in addition to_ Prototype * [TAP5-999|https://issues.apache.org/jira/browse/TAP5-999] tracks work underway to introduce an agnostic tapestry.js layer to allow switching from Prototype to JQuery. See [JavaScript Rewrite] for more info. * [TAPS-1364|https://issues.apache.org/jira/browse/TAP5-1364] lists some starting points for ExtJS integration {float}Tapestry comes with the Prototype and Scriptaculous libraries ... no extra download is required. Tapestry will automatically link into your pages the prototype.js, scriptaculous.js, and effects.js libraries, as well as the Tapestry library, tapestry.js (which largely consists of support for form input validation). Starting with Tapestry 5.3, Underscore is also included.

Prototype and Scriptaculous Versions

Tapestry included prototype only Prototype and scriptaculous Scriptaculous in versions prior to Tapestry 5.4. See Supported Environments and Versions for a matrix of prototype and scriptaculous versions supported by Tapestry.

...