[CONF] Apache Tapestry > Link Components FAQ
Bob Harner edited the page: Link Components FAQ Comment: fixed language param of code macro ... However, you can accomplish the same thing with a little code and markup. For example, to create a link to another page and pass a query parameter, you can replace your PageLink component with a standard tag: Code Block controls true linenumberslanguage truexml In the matching Java class, you can create the Link programmatically: Code Block controls true linenumberslanguage truejava
[CONF] Apache Tapestry > Link Components FAQ
Link Components FAQ Page edited by Howard M. Lewis Ship Changes (1) ... {since} h3. How do I create a Link back to the current page from a component? Sometimes it is useful to create a link back to the current page, but you don't always know the name of the page (the link may appear inside a deeply nested subcomponent). Fortunately, this is easy. {code} refresh page {code} Every component has an extra property, componentResources, added to it: it's the instance of [ComponentResources|http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ComponentResources.html] that represents the link between your code and all of Tapestry's structure around your class. One of the properties of ComponentResources is pageName, the name of the page. By binding the PageLink's page parameter with the "prop:" binding prefix, we ensure that we bind to a computed property; this is necessary because the PageLink.page parameter defaults to the "literal:" binding prefix. As an added benefit, if the page class is ever renamed or moved to a different package, the pageName property will automatically adjust to the new name. {scrollbar} Full Content BeanEditForm FAQ Frequently Asked Questions Component Events FAQ 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). However, you can accomplish the same thing with a little code and markup. For example, to create a link to another page and pass a query parameter, you can replace your PageLink component with a standard tag: "${profilePageLink}">Display Profile (w/ full details) In the matching Java class, you can create the Link programmatically: @Inject private PageRenderLinkSource linkSource; public Link getProfilePageLink() { Link link = linkSource.createPageRenderLinkWithContext(DisplayProfile.class, user); link.addParameterValue("detail", true); return link; } ... and in the DisplayProfile page: public class DisplayProfile { void onActivate(@RequestParameter("detail") boolean detail) { . . . } } The @RequestParameter annotation directs Tapestry to extract the query parameter from the request 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 component event URLs (the type generated by the ActionLink or EventLink components), by injecting the ComponentResources, and invoking method createEventLink(). Added in 5.3 You may also bind a link component's parameters parameter; this is a Map of additional query parameters to add to the URL. The Map keys should be strings, and the Map values will be encoded to strings. Tapestry 5.3 also adds a literal map syntax to the property _expression_ language. How do I create a Link back to the current page from a component? Sometimes it is useful to create a link back to the current page, but you don't always know the name of the page (the link may appear inside a deeply nested subcomponent). Fortunately, this is easy. "prop:componentResources.pageName">refresh page Every component has an extra property, componentResources, added to it: it's the instance of ComponentResources that represents the link between your code and all of Tapestry's structure around your class. One of the properties of ComponentResources is pageName, the name of the page. By binding the PageLink's page parameter with the "prop:" binding prefix, we ensure that we bind to a computed property; this is necessary because the PageLink.page parameter defaults to the "literal:" binding prefix. As an added benefit, if the page class is ever renamed or moved to a different package, the pageName property will automatically adjust to the new name. BeanEditForm FAQ Frequently Asked Questions Component Events FAQ Change Notification Preferences View Online | View Changes
[CONF] Apache Tapestry > Link Components FAQ
Link Components FAQ Page edited by Howard M. Lewis Ship Changes (1) ... {since:since=5.3} You may also bind a link component's {{parameters}} parameter; this is a Map of additional query parameters to add to the URL. The Map keys should be strings, and the Map values will be encoded to strings. Tapestry 5.3 also adds a literal map syntax to the [property _expression_ language|TAPESTRY:Property Expressions]. {since} {scrollbar} Full Content Forms and Form Components Frequently Asked Questions _javascript_ FAQ 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). However, you can accomplish the same thing with a little code and markup. For example, to create a link to another page and pass a query parameter, you can replace your PageLink component with a standard tag: "${profilePageLink}">Display Profile (w/ full details) In the matching Java class, you can create the Link programmatically: @Inject private PageRenderLinkSource linkSource; public Link getProfilePageLink() { Link link = linkSource.createPageRenderLinkWithContext(DisplayProfile.class, user); link.addParameterValue("detail", true); return link; } ... and in the DisplayProfile page: public class DisplayProfile { void onActivate(@RequestParameter("detail") boolean detail) { . . . } } The @RequestParameter annotation directs Tapestry to extract the query parameter from the request 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 component event URLs (the type generated by the ActionLink or EventLink components), by injecting the ComponentResources, and invoking method createEventLink(). Added in 5.3 You may also bind a link component's parameters parameter; this is a Map of additional query parameters to add to the URL. The Map keys should be strings, and the Map values will be encoded to strings. Tapestry 5.3 also adds a literal map syntax to the property _expression_ language. Forms and Form Components Frequently Asked Questions _javascript_ FAQ Change Notification Preferences View Online | View Changes
[CONF] Apache Tapestry > Link Components FAQ
Link Components FAQ Page edited by Howard M. Lewis Ship Changes (2) {scrollbar} h2. Link Components ... A similar technique can be used to add query parmeters to component event URLs (the type generated by the ActionLink or EventLink components), by injecting the ComponentResources, and invoking method {{createEventLink()}}. {scrollbar} Full Content Forms and Form Components Frequently Asked Questions _javascript_ FAQ 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). However, you can accomplish the same thing with a little code and markup. For example, to create a link to another page and pass a query parameter, you can replace your PageLink component with a standard tag: "${profilePageLink}">Display Profile (w/ full details) In the matching Java class, you can create the Link programmatically: @Inject private PageRenderLinkSource linkSource; public Link getProfilePageLink() { Link link = linkSource.createPageRenderLinkWithContext(DisplayProfile.class, user); link.addParameterValue("detail", true); return link; } ... and in the DisplayProfile page: public class DisplayProfile { void onActivate(@RequestParameter("detail") boolean detail) { . . . } } The @RequestParameter annotation directs Tapestry to extract the query parameter from the request 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 component event URLs (the type generated by the ActionLink or EventLink components), by injecting the ComponentResources, and invoking method createEventLink(). Forms and Form Components Frequently Asked Questions _javascript_ FAQ Change Notification Preferences View Online | View Changes
[CONF] Apache Tapestry > Link Components FAQ
Link Components FAQ Page edited by Howard M. Lewis Ship Changes (6) ... 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). However, you can accomplish the same thing with a little code and markup. For example, to create a link to another page and pass a query parameter, you can replace your PageLink component with a standard {{}} tag: a standard {{}} tag: {code:controls=true|linenumbers=true} ... Link link = linkSource.createPageRenderLinkWithContext(DisplayProfile.class, user); link.addParameter("detail", "true"); link.addParameterValue("detail", true); return link; ... {code} The @RequestParameter annotation directs Tapestry to extract the query parameter from the request 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 component event URLs (the type generated by the ActionLink or EventLink URLs, components), by injecting the ComponentResources, and invoking method {{createEventLink()}}. Full Content 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). However, you can accomplish the same thing with a little code and markup. For example, to create a link to another page and pass a query parameter, you can replace your PageLink component with a standard tag: "${profilePageLink}">Display Profile (w/ full details) In the matching Java class, you can create the Link programmatically: @Inject private PageRenderLinkSource linkSource; public Link getProfilePageLink() { Link link = linkSource.createPageRenderLinkWithContext(DisplayProfile.class, user); link.addParameterValue("detail", true); return link; } ... and in the DisplayProfile page: public class DisplayProfile { void onActivate(@RequestParameter("detail") boolean detail) { . . . } } The @RequestParameter annotation directs Tapestry to extract the query parameter from the request 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 component event URLs (the type generated by the ActionLink or EventLink components), by injecting the ComponentResources, and invoking method createEventLink(). Change Notification Preferences View Online | View Changes
[CONF] Apache Tapestry > Link Components FAQ
Link Components FAQ Page edited by Howard M. Lewis Ship Changes (6) ... a standard {{}} tag: {newcode:controls=true|linenumbers=true} {newcode} In the matching Java class, you can create the Link programmatically: {newcode:controls=true|linenumbers=true} @Inject private PageRenderLinkSource linkSource; ... return link; } {newcode} ... and in the DisplayProfile page: {newcode:controls=true|linenumbers=true} public class DisplayProfile { ... } } {newcode} 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). ... Full Content 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). However, you can accomplish the same thing with a little code and markup. For example, to create a link to another page and pass a query parameter, you can replace your PageLink component with a standard tag: "${profilePageLink}">Display Profile (w/ full details) In the matching Java class, you can create the Link programmatically: @Inject private PageRenderLinkSource linkSource; public Link getProfilePageLink() { Link link = linkSource.createPageRenderLinkWithContext(DisplayProfile.class, user); link.addParameter("detail", "true"); return link; } ... and in the DisplayProfile page: public class DisplayProfile { 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(). Change Notification Preferences View Online | View Changes
[CONF] Apache Tapestry > Link Components FAQ
Link Components FAQ Page edited by Howard M. Lewis Ship Changes (2) ... {code} ... and in the ProfilePage: DisplayProfile page: {code} public class ProfilePage DisplayProfile { void onActivate(@RequestParameter("detail") boolean detail) ... Full Content 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). However, you can accomplish the same thing with a little code and markup. For example, to create a link to another page and pass a query parameter, you can replace your PageLink component with a standard tag: "${profilePageLink}">Display Profile (w/ full details) In the matching Java class, you can create the Link programmatically: @Inject private PageRenderLinkSource linkSource; public Link getProfilePageLink() { Link link = linkSource.createPageRenderLinkWithContext(DisplayProfile.class, user); link.addParameter("detail", "true"); return link; } ... and in the DisplayProfile page: public class DisplayProfile { 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(). Change Notification Preferences View Online | View Changes
[CONF] Apache Tapestry > Link Components FAQ
Link Components FAQ Page edited by Howard M. Lewis Ship Changes (2) h2. Link Components h3. 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} ... and in the ProfilePage: {code} public class ProfilePage { void onActivate(@RequestParameter("detail") boolean detail) { . . . } } {code} 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()}}. Full Content 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). However, you can accomplish the same thing with a little code and markup. For example, to create a link to another page and pass a query parameter, you can replace your PageLink component with a standard tag: "${profilePageLink}">Display Profile (w/ full details) In the matching Java class, you can create the Link programmatically: @Inject private PageRenderLinkSource linkSource; public Link getProfilePageLink() { Link link = linkSource.createPageRenderLinkWithContext(DisplayProfile.class, user); link.addParameter("detail", "true"); return link; } ... and in the ProfilePage: 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(). Change Notification Preferences View Online | View Changes
[CONF] Apache Tapestry > Link Components FAQ
Link Components FAQ Page added by Howard M. Lewis Ship Link Components How do I add query parameters 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). However, you can accomplish the same thing with a little code and markup. For example, to create a link to another page and pass a query parameter, you can replace your PageLink component with a standard tag: "${profilePageLink}">Display Profile (w/ full details) In the matching Java class, you can create the Link programmatically: @Inject private PageRenderLinkSource linkSource; public Link getProfilePageLink() { Link link = linkSource.createPageRenderLinkWithContext(DisplayProfile.class, user); link.addParameter("detail", "true"); return link; } A similar technique can be used to add query parmeters to ActionLink or EventLink URLs, by injecting the ComponentResources, and invoking method createEventLink(). Change Notification Preferences View Online