开发者

using images for links with <wicket:link>

开发者 https://www.devze.com 2023-03-10 09:55 出处:网络
I\'m trying to use an image for a link like so: <wicket:link> <a href=\"UploadPage.html\"> <img src=\"/logo.png\"/>

I'm trying to use an image for a link like so:

<wicket:link>
    <a href="UploadPage.html">
        <img src="/logo.png"/>
    </a>
</wicket:link>

In the rendered HTML, the href of the <a> is correctly set to my upload page.

But curiously, Wicket adds onclick=window.location.href='/logo.png' to the <img> tag. The end result is that clicking on the logo loads the logo itself, rather than the upload page.

A simple work-around is to not use <wicket:link>, and hard-code the url to my upload page, but I'd like to know if there i开发者_如何学Pythons a proper solution to this.


For me it helped to add empty onClick (Wicket 1.5):

<li><a class="current" href="main">
   <img onClick="" src="img/icons/home.png"/>
</a></li>

after this, the link points to the page, not the image itself


Add the following in your html:

<a wicket:id="linkID"><img src="/logo.png"/></a>

Add the following in the corresponding java class:

add(new PageLink<Void>("linkID", new YourWicketPage()));

Or for more generic purposes:

add(new Link<Void>("linkID") {
    @Override
    public void onClick()
    {
        // do whatever you want when the link/image is clicked
    }
);

Note that I gave the Link a Void model, since a model doesn't seem necessary to me in this case. However, it is imaginable that given a certain context a model for the link should be used.


did you already check out the answer in How to make a wicket link appear as an image?

Which wicket version do you use?


you have maybe forgotten the quote on the "onclick" :

onclick="window.location.href='/logo.png'"


Just to mention: using full url for src tag should help (http://blah/logo.png) but it's not elegent or portable solution. Perhaps it's a wicket bug. Maybe consider using div with css instead?

0

精彩评论

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