Frage

I have a repository storing many images somewhere on the server. I want to be able to create a dynamic Image object with one of the images stored in my repository.

I am using wicket 1.5.7. I saw this example somewhere

1) Created the FileResource class:

public class FileResource extends WebResource { 
private static final long serialVersionUID = 1L; 

private File file; 

public FileResource(File file) { 
    this.file = file; 
} 

@Override 
public IResourceStream getResourceStream() { 
    return new FileResourceStream(file); 
} 
}

2) In MyPage.java:

File imageFile = new File("local_path_to_image"); 
Image myImage = new Image("myImage", new FileResource(imageFile)); 
add(myImage);

3) In MyPage.html:

<i-m-g wicket:id="myImage" />

But this is not working in my case because WebResource is not available in my wicket 1.5.

I have also studied this link in wicket action. But I am a wicket bignner i could not understand much.

I am making a project in which user when click on a product a modal window open with the product name. I also want to include the product image on my modal window inside a panel. Images are stored on my server in a directory.

Any help and advices appreciated! Thanks in advance.

War es hilfreich?

Lösung

finally i settled on this code. I am passing image file name and creating image.

add(new NonCachingImage("imgPlc", new AbstractReadOnlyModel<DynamicImageResource>(){
          @Override public DynamicImageResource getObject() {
            DynamicImageResource dir = new DynamicImageResource() {
              @Override protected byte[] getImageData(Attributes attributes) {
                  StringValue name = parameters.get("name");
                  byte[] imageBytes = null;
                    if(name.isEmpty() == false)
                        imageBytes = getImageAsBytes(name.toString());

                    return imageBytes;
              }
            };
            dir.setFormat("image/png");
            return dir;
          }
        }));
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top