Variable Parameters (2)

Mode
Create
Person Id
 
Return
Look at the URL of this page. It is the page render request from the PageLink, and the activation context is at the end.

References: If, EventContext, Type Coercion, ValueEncoder, PageLink, Page Render Requests, Page Activation.

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>Variable Parameters (2)</h3>
    
    <div class="eg">
        <t:if test="message">
            <div class="alert alert-danger">
                ${message}
            </div>
        </t:if>
        <t:if test="!message">
            <t:beandisplay object="this" include="mode,personId"/>
        </t:if>

        <t:pagelink t:page="examples/navigation/VariableParameters1">Return</t:pagelink>
    </div>

    Look at the URL of this page. 
    It is the page render request from the PageLink, and the <strong>activation context</strong> is at the end.<br/><br/>
    
    References: 
    <a href="http://tapestry.apache.org/5.4/apidocs/org/apache/tapestry5/corelib/components/If.html">If</a>, 
    <a href="http://tapestry.apache.org/5.4/apidocs/org/apache/tapestry5/EventContext.html">EventContext</a>, 
    <a href="http://tapestry.apache.org/typecoercer-service.html">Type Coercion</a>, 
    <a href="http://tapestry.apache.org/5.4/apidocs/org/apache/tapestry5/ValueEncoder.html">ValueEncoder</a>, 
    <a href="http://tapestry.apache.org/5.4/apidocs/org/apache/tapestry5/corelib/components/PageLink.html">PageLink</a>, 
    <a href="http://tapestry.apache.org/page-navigation.html#PageNavigation-PageRenderRequests">Page Render Requests</a>, 
    <a href="http://tapestry.apache.org/page-navigation.html#PageNavigation-Pageactivation">Page Activation</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/navigation/VariableParameters2.tml"/>
        <t:sourcecodetab src="/web/src/main/java/jumpstart/web/pages/examples/navigation/VariableParameters2.java"/>
        <t:sourcecodetab src="/web/src/main/resources/META-INF/assets/css/examples/plain.css"/>
        <t:sourcecodetab src="/web/src/main/java/jumpstart/web/models/Mode.java"/>
    </t:tabgroup>
</body>
</html>


package jumpstart.web.pages.examples.navigation;

import jumpstart.web.models.Mode;

import org.apache.tapestry5.EventContext;
import org.apache.tapestry5.annotations.Import;
import org.apache.tapestry5.annotations.Property;

@Import(stylesheet = "css/examples/plain.css")
public class VariableParameters2 {

    // The activation context

    @Property
    private Long personId;

    @Property
    private Mode mode;
    
    @Property
    private String message;

    // The code

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

    void onActivate(EventContext eventContext) {
        
        int parameterCount = eventContext.getCount();
        
        if (parameterCount == 1) {
            mode = eventContext.get(Mode.class, 0);
        }
        else if (parameterCount == 2) {
            mode = eventContext.get(Mode.class, 0);
            personId = eventContext.get(Long.class, 1);
        }
        else {
            message = "Wrong number of parameters received. Expected 1 or 2, found " + parameterCount + ".";
        }
        
    }

}


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


package jumpstart.web.models;

public enum Mode {
    CREATE, REVIEW, UPDATE, DELETE;
}