javacssimagewicketwicket-7

Displays only the first open image (wicket)


My programm should display avatars(images) for users by their id which is stored in the database. Images stored on disk. I use BufferedDynamicImageResource for display image but the problem is that always the picture that was opened first is displayed. How to fix it?

Image reading:

public ResourceReference getImage() {
    return new ResourceReference(UserPage.class, "image") {
        private static final long serialVersionUID = 2127616487187967396L;

        @Override
        public IResource getResource() {
            BufferedImage image = null;
            File f = null;

            //read image
            try {
                f = new File("PATH");
                image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
                image = ImageIO.read(new FileImageInputStream(f));
                System.out.println("Reading complete.");
            } catch (IOException e) {
                System.out.println("Error: " + e);
            }
            BufferedDynamicImageResource resource = new BufferedDynamicImageResource();
            resource.setImage(image);
            return resource;
        }
    };
}

Function call:

form.add(new Image("userImg", getImage()));

I'm using Wicket 7.8.0


Solution

  • I think your problem is related to caching in the browser. Try to use NonCachingImage instead of Image component.