Laura
Laura

Reputation: 181

Apache wicket - Add image using an http URL as src

I'm trying to add an img tag to a wicket page. I have not the image as file, I have its URL. I retrieve the URL using a REST service that is consumed in the page constructor.

I tried the following code, but it didn't work (I got a Failed to find markup file associated exception):

image = new Image("chart-img", title);
add(image);
image.getMarkupAttributes().put("src", url);

Can anyone help me?

Thanks Laura

Upvotes: 1

Views: 2455

Answers (3)

martin-g
martin-g

Reputation: 17513

Since some time there is also org.apache.wicket.markup.html.image.ExternalImage for exactly this use case.

Upvotes: 2

soorapadman
soorapadman

Reputation: 4509

You can try this also

Image image = new Image("chart-img", "");
image.add(new AttributeModifier("src", url);
image.add(new AttributeModifier("title", title);
add(image);

Upvotes: 2

svenmeier
svenmeier

Reputation: 5681

You just use a WebmarkupContainer for that:

image = new WebMarkupContainer("chart-img") {
  protected void onComponentTag(final ComponentTag tag)
  {
    super.onComponentTag(tag);

    tag.put("src", url);
    tag.put("title", title);
  }
};
add(image)

Upvotes: 2

Related Questions