Re: Download serves empty files with correct number of pages !?!

2015-03-31 Thread ChambreNoire
Nevermind I just used a ResourceLink and it works fine!

--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Download-serves-empty-files-with-correct-number-of-pages-tp4670117p4670128.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



Re: Download serves empty files with correct number of pages !?!

2015-03-31 Thread ChambreNoire
Is there an easy way of overloading the ContentDisposition.ATTACHMENT already
used in DownloadLink?

--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Download-serves-empty-files-with-correct-number-of-pages-tp4670117p4670127.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



Re: Download serves empty files with correct number of pages !?!

2015-03-31 Thread Francois Meillet
org.apache.wicket.request.resource.ContentDisposition
ContentDisposition.INLINE
ContentDisposition.ATTACHMENT

resourceResponse.setContentDisposition(contentDisposition);

François 








Le 31 mars 2015 à 13:35, ChambreNoire  a écrit :

> OK so the empty PDFs where due to some strangeness with the build config
> which is fixed. The filename and extensions are added by
> item.getModelObject().getFile(). So it works fine now however using
> DownloadLink the file still downloads rather than is opened in a new tab. 
> 
> Any ideas?
> 
> --
> View this message in context: 
> http://apache-wicket.1842946.n4.nabble.com/Download-serves-empty-files-with-correct-number-of-pages-tp4670117p4670125.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
> 



Re: Download serves empty files with correct number of pages !?!

2015-03-31 Thread ChambreNoire
OK so the empty PDFs where due to some strangeness with the build config
which is fixed. The filename and extensions are added by
item.getModelObject().getFile(). So it works fine now however using
DownloadLink the file still downloads rather than is opened in a new tab. 

Any ideas?

--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Download-serves-empty-files-with-correct-number-of-pages-tp4670117p4670125.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



Re: Download serves empty files with correct number of pages !?!

2015-03-30 Thread Martin Grigorov
On Mon, Mar 30, 2015 at 7:32 PM, ChambreNoire  wrote:

> I was using the AjaxDownload outlined in
>
> https://cwiki.apache.org/confluence/display/WICKET/AJAX+update+and+file+download+in+one+blow
> before with the same problem.
>
> I switched to DownloadLink :
>
> IModel model = new LoadableDetachableModel() {
>
> @Override
> protected File load() {
>
> File path;
> try {
> path = new ClassPathResource("descriptors/hc").getFile();
>

'hc' has no extension. Neither the server, nor the browser will have idea
how to present it. So I think it is expected that the browser downloads it
instead of showing it in a tab/window.


> } catch (IOException exception) {
> return null;
> }
> return new File(path, item.getModelObject().getFile());
> }
> };
>
> add(new DownloadLink(ID_ALARM, model) {
>
> @Override
> protected void onComponentTag(ComponentTag tag) {
> super.onComponentTag(tag);
>
> tag.getAttributes().put("target", "_blank");
> }
> });
>
> Now the file downloads rather than opening in a new tab and it's still
> blank
> with the correct number of pages...
>

"correct number of pages"
I'd say the correct file is delivered. It is your viewer that doesn't
represent it correctly.
Check the sizes of the original file and the downloaded one.
I guess the file is binary so also try with 'cmp' (Linux command line) or
something similar.


>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Download-serves-empty-files-with-correct-number-of-pages-tp4670117p4670123.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
>
>


Re: Download serves empty files with correct number of pages !?!

2015-03-30 Thread ChambreNoire
I was using the AjaxDownload outlined in
https://cwiki.apache.org/confluence/display/WICKET/AJAX+update+and+file+download+in+one+blow
before with the same problem.

I switched to DownloadLink :

IModel model = new LoadableDetachableModel() {

@Override
protected File load() {

File path;
try {
path = new ClassPathResource("descriptors/hc").getFile();
} catch (IOException exception) {
return null;
}
return new File(path, item.getModelObject().getFile());
}
};

add(new DownloadLink(ID_ALARM, model) {

@Override
protected void onComponentTag(ComponentTag tag) {
super.onComponentTag(tag);

tag.getAttributes().put("target", "_blank");
}
});

Now the file downloads rather than opening in a new tab and it's still blank
with the correct number of pages...

--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Download-serves-empty-files-with-correct-number-of-pages-tp4670117p4670123.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



Re: Download serves empty files with correct number of pages !?!

2015-03-30 Thread ChambreNoire
Francois Meillet wrote
> path = new ClassPathResource("descriptors/hc").getFile(); 
> the path isn't null ?

Nope. By the time we get to the line :

return new FileResourceStream(new File(path, getModelObject().getFile()));

the path isn't null and this ends up instantiating a FileResourceStream with
a file that both has the correct path and exist()s...

--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Download-serves-empty-files-with-correct-number-of-pages-tp4670117p4670121.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



Re: Download serves empty files with correct number of pages !?!

2015-03-30 Thread Martin Grigorov
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  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 implements IResourceListener {
>
> private IResource resource;
>
> AlarmLink(String id, final IModel 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
>
>


Re: Download serves empty files with correct number of pages !?!

2015-03-30 Thread Francois Meillet
path = new ClassPathResource("descriptors/hc").getFile(); 
the path isn't null ?


François 








Le 30 mars 2015 à 18:03, ChambreNoire  a écrit :

> Sure but no exception is thrown!
> 
> --
> View this message in context: 
> http://apache-wicket.1842946.n4.nabble.com/Download-serves-empty-files-with-correct-number-of-pages-tp4670117p4670119.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
> 



Re: Download serves empty files with correct number of pages !?!

2015-03-30 Thread ChambreNoire
Sure but no exception is thrown!

--
View this message in context: 
http://apache-wicket.1842946.n4.nabble.com/Download-serves-empty-files-with-correct-number-of-pages-tp4670117p4670119.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



Re: Download serves empty files with correct number of pages !?!

2015-03-30 Thread Francois Meillet
printing the exception could help

} catch (IOException exception) {
return null;   
--> print stack
}


François 








Le 30 mars 2015 à 17:44, ChambreNoire  a écrit :

> 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 implements IResourceListener {
> 
>private IResource resource;
> 
>AlarmLink(String id, final IModel 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
> 



Download serves empty files with correct number of pages !?!

2015-03-30 Thread ChambreNoire
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 implements IResourceListener {

private IResource resource;

AlarmLink(String id, final IModel 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