How to put a parameter on a wicket link in HTML?
Wicket has a couple of options for creating links.
E.g. this
<wicket:link><a href="Page2.html?productId=1694969292874602935">Go to Page 2
</a></wicket:link>
This shows it passing in a parameter. However, we cant use as we need the linked to page to popup, and :link autolink page doesnt do this.
The only other way to do a link is like this:
<a href="#" wicket:id="launchlink">click here</a>
The question is, using the above notation, How to I give it a parameter the designers can enter? Something like this:
<a href="#" wicket:id="launchlink" wicket:params="productid=2342">click here</a>
Any ideas?
We开发者_运维问答 could mount the page, then use a hard coded html link, e.g.
<a href="/mount/launch/?productid=asdf">click here</a>
However, we specifically dont want this link to be bookmarkable as its dependent on logged in session etc.
Ideally, we would want to be able to add some parameters dynamically, and use some that the designer has manually added to the html page. This sounds too extreme to be possible, but you never know?
Use BookmarkablePageLink, override its onInitialize() method and use org.apache.wicket.Component.getMarkupAttributes() to get the custom attribute value and append it to the link with org.apache.wicket.markup.html.link.BookmarkablePageLink.setParameter(String, String).
Write your own Link implementation.
<a href="#" wicket:id="launchlink" wicket:params="productid=2342">click here</a>
Therefore You have to retrieve the markup stream. Then the parameters could be extracted with a regular expression. But You should use another namespace to avoid conflicts.
To get started, look for:
- Component#findMarkupStream()
- Component#locateMarkupStream()
- or Component#onRender(MarkupStream) to catch the MarkupStream on your own.
This is not a ready-for-use answer, but I think it can be done without much code.
精彩评论