Action Links

ActionLink is very similar to EventLink. ActionLink is probably no longer needed but it is still supported.

The first big difference between ActionLink and EventLink is this:

Here are 3 ActionLinks. They send their ids: addX, addY, and clear:
Count = 0.
Add 1
Add 2
Clear

The links above have URLs like these:

The second big difference between ActionLink and EventLink is server-side:

So, whereas in the EventLinks example we had onAdd(int count) and onClear(), in this ActionLinks example we have onActionFromAddX(int count), onActionFromAddY(int count), and onActionFromClear().

In the rest of JumpStart we will use EventLink, not ActionLink.

References: ActionLink, Page Navigation, Component Events.

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>Action Links</h3>
    
    <p>ActionLink is very similar to EventLink. ActionLink is 
    <a href="http://tapestry.1045711.n5.nabble.com/What-ist-the-advantage-of-ActionLink-compared-to-EventLink-td2419735.html">
    probably no longer needed</a> but it is 
    <a href="http://tapestry.1045711.n5.nabble.com/EventLInk-vs-ActionLink-td3390203.html">still supported</a>.</p>
    
    <p>The first big difference between ActionLink and EventLink is this:</p>
    <ul>
        <li>ActionLink sends its id, not an event name.</li>
    </ul>

    Here are 3 ActionLinks. They send their ids: <em>addX</em>, <em>addY</em>, and <em>clear</em>:
        
    <div class="eg"> 
        <div class="alert alert-info">
            Count = ${count}.
        </div>
        
        <t:actionlink t:id="addX" t:context="literal:1">Add 1</t:actionlink><br/> 
        <t:actionlink t:id="addY" t:context="literal:2">Add 2</t:actionlink><br/>  
        <t:actionlink t:id="clear">Clear</t:actionlink>
    </div>    

    <p>The links above have URLs like these:</p>
    <ul>
        <li><code>http://thehost/jumpstart/examples/input/actionlinks:addx/1?t:ac=n</code></li>
        <li><code>http://thehost/jumpstart/examples/input/actionlinks:addy/2?t:ac=n</code></li>
        <li><code>http://thehost/jumpstart/examples/input/actionlinks:clear?t:ac=n</code></li>
    </ul>
    
    <p>The second big difference between ActionLink and EventLink is server-side:</p>
    <ul>
        <li>ActionLink always "bubbles up" the same event: <em>action</em>.</li>
    </ul>
    
    So, whereas in the EventLinks example we had <code>onAdd(int count)</code> and <code>onClear()</code>, 
    in this ActionLinks example we have <code>onActionFromAddX(int count)</code>, 
    <code>onActionFromAddY(int count)</code>, and <code>onActionFromClear()</code>.<br/><br/>
    
    In the rest of JumpStart we will use EventLink, not ActionLink.<br/><br/>

    References: 
    <a href="http://tapestry.apache.org/5.4/apidocs/org/apache/tapestry5/corelib/components/ActionLink.html">ActionLink</a>, 
    <a href="http://tapestry.apache.org/page-navigation.html">Page Navigation</a>, 
    <a href="http://tapestry.apache.org/component-events.html">Component Events</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/ActionLinks.tml"/>
        <t:sourcecodetab src="/web/src/main/java/jumpstart/web/pages/examples/input/ActionLinks.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.annotations.Import;
import org.apache.tapestry5.annotations.Property;

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

    // Screen fields
    
    @Property
    private int count;
    
    // The code

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

    void onActivate(int count) {
        this.count = count;
    }

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

    int onPassivate() {
        return count;
    }

    void onActionFromAddX(int amount) {
        count += amount;
    }
    
    void onActionFromAddY(int amount) {
        count += amount;
    }
    
    void onActionFromClear() {
        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;
}