开发者

Simple ImageButton

开发者 https://www.devze.com 2023-03-23 22:53 出处:网络
I want to make a simple ImageButton from an existing HTML markup: <input type=\"image\" wicket:id=\"enter\" src=\"images/enter.jpg\" />

I want to make a simple ImageButton from an existing HTML markup:

<input type="image" wicket:id="enter" src="images/enter.jpg" />

images dir is in the root of the webapp. Java code is:

add(new ImageButton("enter"));

But image isn't displayed. What's the most easiest way to make it work?

After further investigation I see that Wicket modifies src attribute:

src="resources/com.mycomp...Class/images/enter_en.jpg

It would be grea开发者_如何学Pythont to leave src attribute unmodified.


So here's now my comment in answer form:

If the image is a static file, a simple Button will do.

ImageButton is only for cases where the image in question is a Wicket resource itself. This is quite useful if your image is dynamically generated, comes from a database or if your images are locale/language dependent.


Have you tried this?

add(new ImageButton("enter", new ResourceReference(AClass.class, "images/enter.jpg");

Note that enter.jpg must be placed in an 'images' directory relative to the location of your AClass file.

See this for more information on ResrouceReference

Looking at the source for ImageButton, I also see the constructor

ImageButton(String, Resource)

which may be worth investigating further.

0

精彩评论

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