bumaklion
bumaklion

Reputation: 171

Presenting file (pdf / tiff / png) content in wicket 1.5

So I've run in to a problem that I can't seem to solve on my own.

I want to present a file in an iFrame. The file can either be pdf, png or tiff, and I don't know which on beforehand. The pdfs and tiffs should be presented with different actions (printing, saving to disk etc) - I rely on browser plug-ins for this.

What I do is this;
Java:

public ContentPanel(String id, final Atatchment attachment) {
    super(id);

    ResourceReference rr = new ResourceReference(attachment.getName()) {
        private static final long serialVersionUID = 1L;

        @Override
        public IResource getResource() {
            return new ByteArrayResource(attachment.getMimeType(), attachment.getByteArray());
        }
    };

    WebMarkupContainer wmc = new WebMarkupContainer("myIframe");
    wmc.add(new AttributeModifier("src", (String) urlFor(rr, null)));
    add(wmc);
}


HTML:

<body>
    <wicket:panel>
        <iframe wicket:id="myIframe" src=""></iframe>
    </wicket:panel>
</body>

This results in a 404 ("The requested resource is not availible"). The thing is, when I had some of the files cached they were presented the way I want them to be.

Thanks in advance!
Olle

Upvotes: 2

Views: 2192

Answers (1)

bumaklion
bumaklion

Reputation: 171

The problem was the the resource was not registered in the application. Just added:

    if (rr.canBeRegistered()) {
        getApplication().getResourceReferenceRegistry().registerResourceReference(rr);
    }

And it works!

Upvotes: 2

Related Questions