How to put a parameter on a wicket link in HTML?

人盡茶涼 提交于 2020-01-15 11:09:43

问题


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?


回答1:


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).




回答2:


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.



来源:https://stackoverflow.com/questions/6726572/how-to-put-a-parameter-on-a-wicket-link-in-html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!