Re: [Wicket-user] Downloading a file generated on the fly

2006-07-11 Thread Levy, Jeremy




Cool thanks,  I used the anonymous IRequestTarget 
strategy...


From: [EMAIL PROTECTED] 
[mailto:[EMAIL PROTECTED] On Behalf Of Igor 
VaynbergSent: Tuesday, July 11, 2006 1:11 PMTo: 
wicket-user@lists.sourceforge.netSubject: Re: [Wicket-user] 
Downloading a file generated on the fly
string target already does the streams.copy thing in its respond so 
you can just dorespond() { ... 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 VaynbergSent: Tuesday, July 11, 2006 12:21 
  PMTo: wicket-user@lists.sourceforge.net
  Subject: Re: [Wicket-user] Downloading a file generated on 
  the fly
  
  
  while 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 AMTo: Levy, 
JeremySubject: 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 
BaseFormhttp://svn.sourceforge.net/viewcvs.cgi/oscon2006/oscon2006/src/java/oscon2006/web/DatabaseQueryForm.java?view=markup&rev=91http://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?  

  

Re: [Wicket-user] Downloading a file generated on the fly

2006-07-11 Thread Igor Vaynberg
string target already does the streams.copy thing in its respond so you can just dorespond() { ... 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; }-IgorOn 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 
VaynbergSent: Tuesday, July 11, 2006 12:21 PMTo: 
wicket-user@lists.sourceforge.net
Subject: Re: [Wicket-user] 
Downloading a file generated on the fly
while 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 AMTo: Levy, 
  JeremySubject: 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 

Re: [Wicket-user] Downloading a file generated on the fly

2006-07-11 Thread Levy, Jeremy




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 
VaynbergSent: Tuesday, July 11, 2006 12:21 PMTo: 
wicket-user@lists.sourceforge.netSubject: Re: [Wicket-user] 
Downloading a file generated on the fly
while 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 AMTo: Levy, 
  JeremySubject: 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 
  BaseFormhttp://svn.sourceforge.net/viewcvs.cgi/oscon2006/oscon2006/src/java/oscon2006/web/DatabaseQueryForm.java?view=markup&rev=91http://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 Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
  
___Wicket-user mailing listWicket-user@lists.sourceforge.net

https://lists.sour

Re: [Wicket-user] Downloading a file generated on the fly

2006-07-11 Thread Igor Vaynberg
while this works it is a bit hacky. it would be better to let the requesttarget's response method produce the output.-IgorOn 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 
AMTo: Levy, JeremySubject: 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=60Levy, 
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 Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
  
___Wicket-user mailing listWicket-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.nethttps://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


Re: [Wicket-user] Downloading a file generated on the fly

2006-07-11 Thread Levy, Jeremy




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 
AMTo: Levy, JeremySubject: 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 
BaseFormhttp://svn.sourceforge.net/viewcvs.cgi/oscon2006/oscon2006/src/java/oscon2006/web/DatabaseQueryForm.java?view=markup&rev=91http://svn.sourceforge.net/viewcvs.cgi/oscon2006/oscon2006/src/java/oscon2006/web/BaseForm.java?view=markup&rev=60Levy, 
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 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


Re: [Wicket-user] Downloading a file generated on the fly

2006-07-11 Thread Igor Vaynberg
dont take this liteteraly but here it isadd(new Link("link) {    onclick() {   String txt=generatefile();   WebRequestCycle.get().setResponseTarget(new ResponseTarget() {  void respond() {
 WebResponse r=WebRequestCycle.get().getResponse(); r.setAttachmentHeader("filename"); Streams.copy(new StringInputStream(txt), r.getOutputStream
);    }  }}-Igor    On 7/11/06, Levy, Jeremy <
[EMAIL PROTECTED]> 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 Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642___Wicket-user mailing list
Wicket-user@lists.sourceforge.nethttps://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