Hi,

Why don't you use DownloadLink or ResourceLink ?
At least check their sources for inspiration.

Martin Grigorov
Freelancer, available for hire!
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Mon, Mar 30, 2015 at 6:44 PM, ChambreNoire <a...@tentelemed.com> wrote:

> Hello,
>
> I have a strange problem. Ever since I have moved the files I'm linking to
> in the following code to the classpath, they are downloading as empty files
> but *with the correct number of pages*!
>
> Any ideas?
>
> Thanks
>
> class AlarmLink extends Link<Alarm> implements IResourceListener {
>
>     private IResource resource;
>
>     AlarmLink(String id, final IModel<Alarm> model) {
>         super(id, model);
>
>         resource = new ResourceStreamResource(null) {
>
>             @Override
>             protected IResourceStream getResourceStream() {
>
>                 File path;
>                 try {
>                     path = new
> ClassPathResource("descriptors/hc").getFile();
>                 } catch (IOException exception) {
>                     return null;
>                 }
>                 return new FileResourceStream(new File(path,
> getModelObject().getFile()));
>             }
>         };
>     }
>
>     public final void onResourceRequested() {
>
>         Attributes a = new Attributes(RequestCycle.get().getRequest(),
> RequestCycle.get().getResponse(), null);
>         resource.respond(a);
>         onLinkClicked();
>     }
>
>     @Override
>     protected final CharSequence getURL() {
>         return urlFor(IResourceListener.INTERFACE, null);
>     }
>
>     @Override
>     public void onClick() {}
>
>     @Override
>     public IModel<?> getBody() {
>         return PropertyModel.of(getModel(), "label");
>     }
>
>     @Override
>     protected void onComponentTag(ComponentTag tag) {
>         super.onComponentTag(tag);
>         tag.getAttributes().put("target", "_blank");
>     }
> }
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Download-serves-empty-files-with-correct-number-of-pages-tp4670117.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