Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Link Components

How do I add query parameters to a PageLink or ActionLink?

These components do not have parameters to allow you to specify query parameters for the link; they both allow you to specify a context (one or more values to encode into the request path).

...

Code Block
  @Inject
  private PageRenderLinkSource linkSource;

  public Link getProfilePageLink()
  {
    Link link = linkSource.createPageRenderLinkWithContext(DisplayProfile.class, user);

    link.addParameter("detail", "true");

    return link;
  }

... and in the ProfilePage:

Code Block

public class ProfilePage
{
  void onActivate(@RequestParameter("detail") boolean detail)
  {
    . . .
  }
}

The @RequestParameter annotation directs Tapestry to extract the query parameter and coerce it to type boolean. You can use any reasonable type for such a parameter (int, long and Date are common).

A similar technique can be used to add query parmeters to ActionLink or EventLink URLs, by injecting the ComponentResources, and invoking method createEventLink().