public class Trigger extends Object
JavaScriptSupport
environmental).Name | Type | Flags | Default | Default Prefix |
---|---|---|---|---|
event | String | literal |
In this example, we are showing how to trigger an event from the template of a page. When the following page is rendered the both instances of the component Trigger publish an arbitrary event.
<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd"> <body> <h1>Trigger Demo</h1> <p> ... </p> <t:trigger event="addAdditionalScriptLinks"/> <p> ... </p> <t:trigger event="provideAdditionalMarkup"/> </body> </html>
Inside the handler method for the event addAdditionalScriptLinks we add a link to a JavaScript file. The handler method for the event provideAdditionalMarkup provides some additional markup. The MarkupWriter is passed as the event context.
public class TriggerDemo { @Environmental private JavaScriptSupport jsSupport; @Inject @Path("context:js/scripts.js") private Asset scripts; public void onAddAdditionalScriptLinks() { jsSupport.importJavaScriptLibrary(scripts); } public void onProvideAdditionalMarkup(MarkupWriter writer) { writer.writeRaw("Hello."); } }
public Trigger()
5.6.3 - Copyright © 2003-2021 The Apache Software Foundation.