You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Shelli Orton <Sh...@sjrb.ca> on 2010/09/29 21:59:20 UTC

Save Data as CSV File

I have a data table and would like the user to be able to save the data
locally as a csv file when they click a link or button.  The docs for
DownloadLink state that it will generate a "save as" dialog which is
exactly what I want, but, it appears to only work with a file that
already exists.  I haven't been able to find any examples of how to use
it, so I could be wrong about that.  I've seen some posts that talk
about using a DynamicWebResource, but I can't find any complete examples
on how to generate/download a file.

What is the "best" way to download a file generated programmatically in
Wicket?

Thanks,
Shelli

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Save Data as CSV File

Posted by Peter Karich <pe...@yahoo.de>.
Hi,

this worked for me:

WebResource export = new WebResource() {

    @Override
    public IResourceStream getResourceStream() {
        return new StringResourceStream(getTweetsAsString(), "text/plain");
    }

    @Override
    protected void setHeaders(WebResponse response) {
        super.setHeaders(response);
        response.setAttachmentHeader("tweets.csv");
    }
};
export.setCacheable(false);
add(new ResourceLink("exportCsvLink", export));

Regards,
Peter.

> I have a data table and would like the user to be able to save the data
> locally as a csv file when they click a link or button.  The docs for
> DownloadLink state that it will generate a "save as" dialog which is
> exactly what I want, but, it appears to only work with a file that
> already exists.  I haven't been able to find any examples of how to use
> it, so I could be wrong about that.  I've seen some posts that talk
> about using a DynamicWebResource, but I can't find any complete examples
> on how to generate/download a file.
>
> What is the "best" way to download a file generated programmatically in
> Wicket?
>
> Thanks,Shelli
>
>   

-- 
http://jetwick.com twitter search prototype


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Save Data as CSV File

Posted by Antoine Angenieux <aa...@clinigrid.com>.
You can use the constructor that takes an IModel<File> and pass a LoadableDetachableModel or AbstractReadOnlyModel in which you generate your file. Don't Forget to call setDeleteAfterDowload(true) on your DownloadLink to avoid filling your drive too fast!

I do that all the times and as usually with Wicket it works just fine ;)

Cheers,

Antoine. 


--
Antoine Angénieux
Associé

Clinigrid
5, avenue Mozart
75016 Paris, France
+336 60 21 09 18
aangenieux@clinigrid.com

Le 29 sept. 2010 à 21:59, "Shelli Orton" <Sh...@sjrb.ca> a écrit :

> I have a data table and would like the user to be able to save the data
> locally as a csv file when they click a link or button.  The docs for
> DownloadLink state that it will generate a "save as" dialog which is
> exactly what I want, but, it appears to only work with a file that
> already exists.  I haven't been able to find any examples of how to use
> it, so I could be wrong about that.  I've seen some posts that talk
> about using a DynamicWebResource, but I can't find any complete examples
> on how to generate/download a file.
> 
> What is the "best" way to download a file generated programmatically in
> Wicket?
> 
> Thanks,
> Shelli
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org