You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

How can I load an image directly from a url?

For example I want to display a picture of a user next to their profile,
but all of the images are served by another machine for better
performance.

    class StaticImage extends WebComponent {

        public StaticImage(String id, IModel model) {
            super(id, model);
        }

        protected void onComponentTag(ComponentTag tag) {
            checkComponentTag(tag, "img");
            tag.put("src", getModelObjectAsString());
        }

    }

    add(new StaticImage("img", new Model("http://foo.com/bar.gif"));

Thanks to Igor Vaynberg

  • No labels