respond() { ... r.setattachmentheader(..); r.setContentType(..) super.respond(); }
or do how i showed you in the first place using an anonymous imple of IRequestTarget directly.
IRequestTarget.detach() { } IRequestTarget.getLock() { return null; }
-Igor
On 7/11/06, Levy, Jeremy <
[EMAIL PROTECTED]> wrote:
I'd like to do it the clean way... When I do this:RequestCycle.get().setRequestTarget(new StringRequestTarget("hello"){
public void respond(){
String txt = "content";
WebResponse r=(WebResponse) WebRequestCycle.get().getResponse();
r.setAttachmentHeader(filename);
r.setContentType(contentType);
try {
Streams.copy(new StringInputStream(txt), r.getOutputStream() );
} catch (IOException ex) {
ex.printStackTrace();
}
}
});The content shows up as "hello" and opens in the browser not as the correct content type, I'm sure I'm using the wrong kind of IRequestTarget, which one should I use? I can't figure out the syntax for EmptyRequestTarget and still override respond().J
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] On Behalf Of Igor Vaynberg
Sent: Tuesday, July 11, 2006 12:21 PM
To: wicket-user@lists.sourceforge.net
Subject: Re: [Wicket-user] Downloading a file generated on the flywhile this works it is a bit hacky. it would be better to let the requesttarget's response method produce the output.
-Igor
On 7/11/06, Levy, Jeremy <[EMAIL PROTECTED]> wrote:Thanks Sean and Igor, based on both your responses I've come up with roughly the following which is working:final String filename = "thefile.csv";
final String contentType = "text/csv";
final String content = "the,content,is,this";
add(new Link("link"){
public void onClick(){
RequestCycle.get().setRequestTarget(EmptyRequestTarget.getInstance());
WebResponse response = (WebResponse) getResponse();
response.setContentType(contentType);
response.setAttachmentHeader(filename);
response.setHeader("Cache-Control", "max-age=0");
OutputStream out = response.getOutputStream();
try {
out.write(content.getBytes());
out.flush();
} catch (IOException ex) {
// ignore
}
}
});
From: Sean Sullivan [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, July 11, 2006 11:16 AM
To: Levy, Jeremy
Subject: Re: [Wicket-user] Downloading a file generated on the fly
Here's an application that I wrote.
The application retrieves data from a database and converts it to an Excel XLS file.
I am sending the XLS file to the web browser via the ServletOutputStream.
Note: DatabaseQueryForm extends BaseForm
http://svn.sourceforge.net/viewcvs.cgi/oscon2006/oscon2006/src/java/oscon2006/web/DatabaseQueryForm.java?view=markup&rev=91
http://svn.sourceforge.net/viewcvs.cgi/oscon2006/oscon2006/src/java/oscon2006/web/BaseForm.java?view=markup&rev=60
Levy, Jeremy wrote:I would like to create a text file on the fly and then create a link which will initiate a download of this file.I checked out the example at http://www.wicket-wiki.org.uk/wiki/index.php/UploadDownload#Downloading_Images . I am thinking that I can do something similar but extend DynamicWebResource. Then use ResourceLink to link to it... Would this work? Is there a better way to do it?J
Important Notice to Recipients:It is important that you do not use e-mail to request, authorize or effect the purchase or sale of any security or commodity, to send fund transfer instructions, or to effect any other transactions. Any such request, orders, or instructions that you send will not be accepted and will not be processed by Morgan Stanley.
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimohttp://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user
Important Notice to Recipients:It is important that you do not use e-mail to request, authorize or effect the purchase or sale of any security or commodity, to send fund transfer instructions, or to effect any other transactions. Any such request, orders, or instructions that you send will not be accepted and will not be processed by Morgan Stanley.
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user
Important Notice to Recipients:It is important that you do not use e-mail to request, authorize or effect the purchase or sale of any security or commodity, to send fund transfer instructions, or to effect any other transactions. Any such request, orders, or instructions that you send will not be accepted and will not be processed by Morgan Stanley.
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Wicket-user mailing list
Wicket-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wicket-user
------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________ Wicket-user mailing list Wicket-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/wicket-user