Class Trigger


  • public class Trigger
    extends Object
    Triggers an arbitrary event during rendering. This is often useful to add JavaScript to a page or a component (via calls to the JavaScriptSupport environmental).
    Since:
    5.2.0
    Component Parameters 
    NameTypeFlagsDefaultDefault Prefix
    eventString  literal

    Examples

    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.

    TriggerDemo.tml

    <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.

    TriggerDemo.java

    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.");
        }
    }
    
    • Constructor Detail