Passing Data Between Pages: by Query String

You asked for partialName=humpty.

Return
This page used a query string to pass its data through the redirection. A query string is a series of name-value pairs that get included in the URL following a question mark. The @ActivationRequestParameter annotation tells Tapestry to put a field in the query string.

This technique may be the most appropriate way to pass filter criteria because, arguably, it produces the most RESTful URL in that situation. Note that the URL can be bookmarked.

References: Query strings in RESTful Web Services, @ActivationRequestParameter, PageRenderLinkSource.

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>Passing Data Between Pages: by Query String</h3>

    <div class="eg">
        <p>You asked for partialName=${partialName}.</p>
        <t:pagelink page="examples/state/PassingDataBetweenPages">Return</t:pagelink>
    </div>

    This page used a <strong>query string</strong> to pass its data through the redirection. A query string is 
    a series of name-value pairs that get included in the URL following a question mark.
    The <code>@ActivationRequestParameter</code> annotation tells Tapestry to put a field in the query string.<br/><br/>
    
    This technique may be the most appropriate way to pass <strong>filter criteria</strong> because, 
    arguably, it produces the most RESTful URL in that situation. Note that the URL can be bookmarked.<br/><br/>

    References: 
    <a href="http://blpsilva.wordpress.com/2008/04/05/query-strings-in-restful-web-services/">
        Query strings in RESTful Web Services</a>, 
    <a href="http://tapestry.apache.org/5.4/apidocs/org/apache/tapestry5/annotations/ActivationRequestParameter.html">@ActivationRequestParameter</a>,
    <a href="http://tapestry.apache.org/5.4/apidocs/org/apache/tapestry5/services/PageRenderLinkSource.html">PageRenderLinkSource</a>.<br/><br/>

    <t:pagelink page="Index">Home</t:pagelink><br/><br/>
    
    <t:tabgroup>
        <t:sourcecodetab src="/web/src/main/java/jumpstart/web/pages/examples/state/PassingByQueryString.tml"/>
        <t:sourcecodetab src="/web/src/main/java/jumpstart/web/pages/examples/state/PassingByQueryString.java"/>
        <t:sourcecodetab src="/web/src/main/resources/META-INF/assets/css/examples/olive.css"/>
    </t:tabgroup>
</body>
</html>


package jumpstart.web.pages.examples.state;

import org.apache.tapestry5.Link;
import org.apache.tapestry5.annotations.ActivationRequestParameter;
import org.apache.tapestry5.annotations.Import;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.services.PageRenderLinkSource;

/**
 * This page demonstrates using a query string to remember data through the redirect. The data will be appended to
 * the page render request URL as a query string.
 */
@Import(stylesheet="css/examples/olive.css")
public class PassingByQueryString {

    // Query string parameters - you are not limited to one.

    @ActivationRequestParameter(value = "partial")
    @Property
    private String partialName;

    // Generally useful bits and pieces

    @Inject
    private PageRenderLinkSource pageRenderLinkSource;

    // The code

    // set() is public so that other pages can use it to get a correct link to this page.

    public Link set(String partialName) {
        this.partialName = partialName;

        return pageRenderLinkSource.createPageRenderLink(this.getClass());
    }
}


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