12

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 is a proper solution to this.

2

5 Answers 5

2

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

1

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.

0
0

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

Which wicket version do you use?

2
  • I'm using Wicket 1.4.17. I'm only trying to link to an internal Wicket page, not an ExternalLink, so the page you reference doesn't really apply. Jul 24, 2011 at 19:26
  • This is rather a comment, not an answer. Oct 14, 2012 at 21:01
0

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

onclick="window.location.href='/logo.png'"
1
  • 1
    I'm not supplying the onclick behavior- Wicket is. Jul 24, 2011 at 19:24
0

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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.