You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Jeffrey Schneller <je...@envisa.com> on 2011/07/14 00:18:25 UTC

BookmarkableLink to download a CSV file

I want to have a link that when hit will download a csv file.  I would
prefer to use a Page or a component that I can use the @SpringBean
notation on so the csv file data can be retrieved via my service layer
beans.

 

I can generate the file using a WebPage with the following in my
constructor for the page where sb is my StringBuilder holding the data.

                                WebResponse response = (WebResponse)
this.getResponse();

                                java.io.OutputStream cout =
response.getOutputStream();

                                try {

 
cout.write(sb.toString().getBytes());

                                                cout.flush();

                                                cout.close();

                                } catch (IOException e) {

                                                // TODO Auto-generated
catch block

                                                e.printStackTrace();

                                }

My page also overrides setHeaders to set the proper headers, ContentType
and Header specifying download and file name.

 

The problem with this is the following 2 errors are thrown:

011-07-13 17:58:23,910 ERROR org.apache.wicket.RequestCycle
RequestCycle:1529 - Markup of type 'html' for component
'com.company.myPage' not found. Enable debug messages for
org.apache.wicket.util.resource to get a list of all filenames tried.:
[Page class = com.company.myPage, id = 4, version = 0]

org.apache.wicket.markup.MarkupNotFoundException: Markup of type 'html'
for component ' com.company.myPage ' not found. Enable debug messages
for org.apache.wicket.util.resource to get a list of all filenames
tried.: [Page class = com.company.myPage, id = 4, version = 0]

 

2011-07-13 17:58:24,549 ERROR
org.apache.wicket.protocol.http.WicketFilter WicketFilter:507 - closing
the buffer error

java.lang.IllegalStateException: getOutputStream() has already been
called for this response

 

 

Any ideas?

 


Re: BookmarkableLink to download a CSV file

Posted by Martin Grigorov <mg...@apache.org>.
see IMarkupResourceStreamProvider

I recommend you to use a resource instead. You can inject the Spring
bean with Injector.get().inject(this) in the constructor

On Thu, Jul 14, 2011 at 1:18 AM, Jeffrey Schneller
<je...@envisa.com> wrote:
> I want to have a link that when hit will download a csv file.  I would
> prefer to use a Page or a component that I can use the @SpringBean
> notation on so the csv file data can be retrieved via my service layer
> beans.
>
>
>
> I can generate the file using a WebPage with the following in my
> constructor for the page where sb is my StringBuilder holding the data.
>
>                                WebResponse response = (WebResponse)
> this.getResponse();
>
>                                java.io.OutputStream cout =
> response.getOutputStream();
>
>                                try {
>
>
> cout.write(sb.toString().getBytes());
>
>                                                cout.flush();
>
>                                                cout.close();
>
>                                } catch (IOException e) {
>
>                                                // TODO Auto-generated
> catch block
>
>                                                e.printStackTrace();
>
>                                }
>
> My page also overrides setHeaders to set the proper headers, ContentType
> and Header specifying download and file name.
>
>
>
> The problem with this is the following 2 errors are thrown:
>
> 011-07-13 17:58:23,910 ERROR org.apache.wicket.RequestCycle
> RequestCycle:1529 - Markup of type 'html' for component
> 'com.company.myPage' not found. Enable debug messages for
> org.apache.wicket.util.resource to get a list of all filenames tried.:
> [Page class = com.company.myPage, id = 4, version = 0]
>
> org.apache.wicket.markup.MarkupNotFoundException: Markup of type 'html'
> for component ' com.company.myPage ' not found. Enable debug messages
> for org.apache.wicket.util.resource to get a list of all filenames
> tried.: [Page class = com.company.myPage, id = 4, version = 0]
>
>
>
> 2011-07-13 17:58:24,549 ERROR
> org.apache.wicket.protocol.http.WicketFilter WicketFilter:507 - closing
> the buffer error
>
> java.lang.IllegalStateException: getOutputStream() has already been
> called for this response
>
>
>
>
>
> Any ideas?
>
>
>
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

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