开发者

Wicket page links do not use mounted URL coding strategy?

开发者 https://www.devze.com 2022-12-16 09:54 出处:网络
In the Wicket Application class I have mounted a page at the location /about mountBookmarkablePage(\"about\", AboutPage.class);

In the Wicket Application class I have mounted a page at the location /about

mountBookmarkablePage("about", AboutPage.class);

I verify that the about page is available at /about. Then in the page which needs a link to the about page, I use the Wicket Link class:

add(new Link("link") {

            @Override
            public void onClick() {
                setResponsePage(AboutPage.class);
            }

        };
)

The links work as expected but the target URL diplayed in the browser status bar when the mouse is over the link looks like

http://localhost:8080/?wicket:interface=:0:linkpage:repeating:1:link::ILinkListener::

A workaround which I have found is to use ExternalLink

new ExternalLink("link", "/about", "about");

This changes the target URL to

http://localhost:8080/about

which is displayed in the browser status bar when the mouse is over the link.

Is there a way to use the mounted URL as the target link with Wicket Link class, or is there a way to get the mount location for a class, so that I can use it to build the link url for AboutPage.class (instead of hard coding it in th开发者_运维问答e ExternalLink constructor)?


For this purpose you should use BookmarkablePageLink (as you're saying you're doing), to set the link label (or any other content for that matter) just call .add(Component... c) since BookmarkablePageLink is actually a MarkupContainer.

So, to create a link to AboutPage.class you need to do this:

BookmarkablePageLink aboutLink = new BookmarkablePageLink("link", AboutPage.class);
aboutLink.add(new Label("linkText", "Go to About page"));
add(aboutLink);

and the matching markup

<a wicket:id="link"><span wicket:id="linkText">Link text goes here</span></a>

Yeppers, it's slightly more verbose but also very easily extensible. If you want to, you can create your own convenience subclass of BookmarkablePageLink called BookmarkableTextLink and have a

new BookmarkableTextLink(String id, Class<Page> pageClass, String linkText);

constructor for it.


Found a solution: the BookmarkablePageLink class

add(new BookmarkablePageLink("link", AboutPage.class));

This solution only has a small problem: the link label can not be set, maybe this can be done by assigning a model.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号