You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wicket.apache.org by Sebastien <se...@gmail.com> on 2017/04/01 14:56:24 UTC
AjaxDownload with IRequestHandler / IResourceStream
Hi devs,
I was wondering if would be possible to change the AjaxDownload a bit so it
works with IRequestHandler or IResourceStream.
Maybe something like this:
AjaxDownload download = new AjaxDownload();
(...)
IResourceStream stream = new DataExporterResourceStreamWriter(new
CSVDataExporter(), provider, columns);
download.initiate(target, stream, "myfilename")
or
IResourceStream stream = new DataExporterResourceStreamWriter(new
CSVDataExporter(), provider, columns);
IRequestHandler handler = new ResourceStreamRequestHandler(stream,
filename));
download.initiate(target, handler)
Thanks in advance & best regards,
Sebastien.
Re: AjaxDownload with IRequestHandler / IResourceStream
Posted by Sven Meier <sv...@meiers.net>.
Hi,
1) often the resource stream holds some big data (e.g. byte array) and
this should definitely not be held in the component tree.
2) please take a look at AjaxDownloadPage in wicket-examples, setting
the file name works fine there (just tested).
Have fun
Sven
On 07.04.2017 21:07, Sebastien wrote:
> You made my day, Sven! I tested it and it works! :)
>
> I have 2 comments:
>
> 1/
>> With this lazy creation of the stream, it is not necessary to hold it in
> the component tree.
> Not sure I understood what you meant but the ajax download still need to be
> hold in the component tree right? As it is an AjaxBehavior, I do not figure
> out how it can work otherwise..
>
> 2/
> The content-type is supplied to the (Abstract)ResourceStreamWriter as
> text/csv. It works too - I can download it - but whatever the filename I
> provide to the ResourceStreamResource, the download dialog always suggest
> ".csv" (no filename, only the extension). Weird, I have to dig into this...
>
> Thanks again & best regards,
> Sebastien.
>
Re: AjaxDownload with IRequestHandler / IResourceStream
Posted by Sebastien <se...@gmail.com>.
You made my day, Sven! I tested it and it works! :)
I have 2 comments:
1/
> With this lazy creation of the stream, it is not necessary to hold it in
the component tree.
Not sure I understood what you meant but the ajax download still need to be
hold in the component tree right? As it is an AjaxBehavior, I do not figure
out how it can work otherwise..
2/
The content-type is supplied to the (Abstract)ResourceStreamWriter as
text/csv. It works too - I can download it - but whatever the filename I
provide to the ResourceStreamResource, the download dialog always suggest
".csv" (no filename, only the extension). Weird, I have to dig into this...
Thanks again & best regards,
Sebastien.
Re: AjaxDownload with IRequestHandler / IResourceStream
Posted by Sebastien <se...@gmail.com>.
Thank you very much Sven !
Yes I prefer to work with IResourceStream because the my export feature
(took from Wicket) already works this way, it just need to be ajaxified ;)
That looks nice! I somehow missed the ResourceStreamResource... I will give
a try in the coming days.
Best regards,
Sebastien.
On Sat, Apr 1, 2017 at 11:10 PM, Sven Meier <sv...@meiers.net> wrote:
> Hi Sebastien,
>
> AjaxDownload uses IResource and ResourceReference as ResourceLink does it
> - IMO these are the most general abstractions for resources in Wicket.
>
> If you prefer to work with an IResourceStream, you can pass a
> ResourceStreamResource to AjaxDownload's constructor:
>
> new AjaxDownload(new ResourceStreamResource() {
> {
> setFileName("myfilename");
> setContentDisposition(ContentDisposition.ATTACHMENT);
> }
> protected IResourceStream getResourceStream(Attributes attributes) {
> return new DataExporterResourceStreamWriter(new
> CSVDataExporter(), provider, columns);
> }
> });
>
> With this lazy creation of the stream, it is not necessary to hold it in
> the component tree.
>
> Have fun
> Sven
>
Re: AjaxDownload with IRequestHandler / IResourceStream
Posted by Sven Meier <sv...@meiers.net>.
Hi Sebastien,
AjaxDownload uses IResource and ResourceReference as ResourceLink does
it - IMO these are the most general abstractions for resources in Wicket.
If you prefer to work with an IResourceStream, you can pass a
ResourceStreamResource to AjaxDownload's constructor:
new AjaxDownload(new ResourceStreamResource() {
{
setFileName("myfilename");
setContentDisposition(ContentDisposition.ATTACHMENT);
}
protected IResourceStream getResourceStream(Attributes attributes) {
return new DataExporterResourceStreamWriter(new
CSVDataExporter(), provider, columns);
}
});
With this lazy creation of the stream, it is not necessary to hold it in
the component tree.
Have fun
Sven
On 01.04.2017 16:56, Sebastien wrote:
> Hi devs,
>
> I was wondering if would be possible to change the AjaxDownload a bit so it
> works with IRequestHandler or IResourceStream.
>
> Maybe something like this:
> AjaxDownload download = new AjaxDownload();
>
> (...)
>
> IResourceStream stream = new DataExporterResourceStreamWriter(new
> CSVDataExporter(), provider, columns);
> download.initiate(target, stream, "myfilename")
>
> or
>
> IResourceStream stream = new DataExporterResourceStreamWriter(new
> CSVDataExporter(), provider, columns);
> IRequestHandler handler = new ResourceStreamRequestHandler(stream,
> filename));
> download.initiate(target, handler)
>
> Thanks in advance & best regards,
> Sebastien.
>