Thanks for the help guys.
I've got it all working correctly now. For other people's future reference.
I think this is the page that Igor was referring to which I pretty much
copied : https://cwiki.apache.org/WICKET/uploaddownload.html
I am retrieving the images from a db as a byte array

//heres a simplified version of my code. Hope this helps someone!

//this is the class that serves up the images
public class ImageResource extends DynamicWebResource {
        private static final long serialVersionUID = 1L;
        
        public ImageResource() {
                super();
        }

        @Override
        protected ResourceState getResourceState() {
                
            ValueMap params = getParameters();
        
            String id = params.getString("id");

            if (id.equals("image1")) {
                //show image 1
                return new ResourceState() {
                      @Override
                      public byte[] getData() {
                          //get the image1 from server....  
                          return image;
                      }

                      @Override
                      public String getContentType() {
                            return "image/jpeg";
                      }
                }
            } else (id.equals("image2")) {
                //show image 2
                return new ResourceState() {
                      @Override
                      public byte[] getData() {
                          //get the image2 from server....  
                          return image;
                      }

                      @Override
                      public String getContentType() {
                            return "image/jpeg";
                      }
                }
           }
      }
}


//this is how I access the image from wicket
add(new Label("profileImage", "") {
        private static final long serialVersionUID = 1L;

        @Override
        protected void onComponentTag(ComponentTag tag) {
                ResourceReference imageResource = new 
ResourceReference("imageResource");
                tag.put("src",
RequestUtils.toAbsolutePath(getRequestCycle().urlFor(imageResource).toString())+"?id=image1");
                super.onComponentTag(tag);
        }
});

//and this needs to be added to the wicket application init method
getSharedResources().add("imageResource", new ImageResource());

-- 
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Dynamically-loading-image-tp3064795p3068044.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to