oguzalb
oguzalb

Reputation: 438

wicket image path without rewrite

I m trying to upload and show images. I get the file, write it to docroot of glassfish application server, then

    Image image = new Image("myimage","images/task.gif");

But i get <img wicket:id="myimage" src="resources/wickcat.MyPage/images/task.gif" />

Is there any way that wicket wont rewrite my src path? Even when i use an http://.... starting src, it writes resources/wickcat.MyPage/http://... which makes no sense at all. I just need it to write "images/task.gif". Any ideas?

Upvotes: 1

Views: 3243

Answers (2)

tetsuo
tetsuo

Reputation: 10896

The Image class assumes the image is a resource located in the classpath.

You could use a WebMarkupContainer with a SimpleAttributeModifier:

WebMarkupContainer img = new WebMarkupContainer("myimage")
    .add(new SimpleAttributeModifier("src", "/images/task.gif"));

It will output the string as is, so you have complete control.

If it is used several times across the application, I'd recommend you to create a component encapsulating this behavior. Something like

public class MyImage extends WebMarkupContainer {
    public MyImage(String id, String path) {
        add(new SimpleAttributeModifier("src", path));
    }
}

Upvotes: 1

Marcelo
Marcelo

Reputation: 11308

There is two ways to do this.

  1. Use <img src="images/task.gif" />. This is if you don't need reference to the component in the class.

  2. Use ContextImage image = new ContextImage("myimage", "images/task.gif");. If you use the ContextImage component, the source will be relative to the Context root, you can even input a model as the relative path to the image.

Upvotes: 6

Related Questions