@OnEvent

If you prefer, you can annotate event handler methods with @OnEvent rather than use the "on" naming convention.
Count = 34.
Add 1
Add 2
Clear
References: @OnEvent, EventLink.

Home


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!-- We need a doctype to allow us to use special characters like &nbsp; 
     We use a "strict" DTD to make IE follow the alignment rules. -->
     
<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_4.xsd">
<body class="container">
    <h3>@OnEvent</h3>

    If you prefer, you can annotate event handler methods with <code>@OnEvent</code> rather than use the "on" naming convention.

    <div class="eg"> 
        Count = ${count}.<br/> 
        <t:eventlink t:event="add" t:context="literal:1">Add 1</t:eventlink><br/> 
        <t:eventlink t:event="add" t:context="literal:2">Add 2</t:eventlink><br/>
        <t:eventlink t:event="clear">Clear</t:eventlink>
    </div>    

    References: 
    <a href="http://tapestry.apache.org/5.4/apidocs/org/apache/tapestry5/annotations/OnEvent.html">@OnEvent</a>, 
    <a href="http://tapestry.apache.org/5.4/apidocs/org/apache/tapestry5/corelib/components/EventLink.html">EventLink</a>.<br/><br/>
    
    <t:pagelink t:page="Index">Home</t:pagelink><br/><br/>

    <t:tabgroup>
        <t:sourcecodetab src="/web/src/main/java/jumpstart/web/pages/examples/input/AtOnEvent.tml"/>
        <t:sourcecodetab src="/web/src/main/java/jumpstart/web/pages/examples/input/AtOnEvent.java"/>
        <t:sourcecodetab src="/web/src/main/resources/META-INF/assets/css/examples/olive.css"/>
    </t:tabgroup>
</body>
</html>



package jumpstart.web.pages.examples.input;

import org.apache.tapestry5.EventConstants;
import org.apache.tapestry5.annotations.Import;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Property;

@Import(stylesheet="css/examples/olive.css")
public class AtOnEvent {

    // Screen fields

    @Property
    private int count;

    // The code

    // onActivate() is called by Tapestry to pass in the activation context from the URL.

    @OnEvent(value = EventConstants.ACTIVATE)
    void startMeUp(int count) {
        this.count = count;
    }

    // onPassivate() is called by Tapestry to get the activation context to put in the URL.

    int onPassivate() {
        return count;
    }

    @OnEvent(value = "add")
    void doSomeAdding(int amount) {
        count += amount;
    }

    @OnEvent(value = "clear")
    void resetTheCount() {
        count = 0;
    }

}


.eg {
                margin: 20px 0;
                padding: 14px;
                color: olive;
                border: 1px solid #ddd;
                border-radius: 6px;
                -webkit-border-radius: 6px;
                -mox-border-radius: 6px;
}