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.

Peter
  • 31
  • 5
George Armhold
  • 30,824
  • 50
  • 153
  • 232

5 Answers5

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

vinga
  • 1,912
  • 20
  • 33
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.

Georgi Khomeriki
  • 674
  • 6
  • 17
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?

Community
  • 1
  • 1
Wintermute
  • 1,521
  • 1
  • 13
  • 34
0

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

onclick="window.location.href='/logo.png'"
lookfire
  • 328
  • 1
  • 4
  • 10
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?

vinga
  • 1,912
  • 20
  • 33