I dont know the subject, I didnt follow up, but this code is working.
downloadLink = new Link("downloadFile"){
private static final long serialVersionUID = 1L;
public void onClick(){
String tableCode = sourceCode;
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
String ContentType = "text";
getResponse().setContentType(ContentType);
((WebResponse)getResponse()).setHeader("Content-Disposition","inline;
filename=\""+fileName+".java\"");
ByteArrayInputStream bais = new ByteArrayInputStream(tableCode.getBytes());
bis = new BufferedInputStream(bais);
bos=new BufferedOutputStream(getResponse().getOutputStream());
byte[] buff=new byte[2048];
int bytesread;
while((bytesread=bis.read(buff,0,buff.length)) != -1) {
bos.write(buff,0,bytesread);
}
bos.flush();
} catch (Exception e) {
e.printStackTrace();
} finally{
try {
bos.close();bos=null;
bis.close();bis=null;
} catch (Exception e) {
}
}
}
};
Eelco Hillenius <[EMAIL PROTECTED]> wrote:
On 10/6/07, Stanczak Group wrote:
> Well, I still don't see a way to get around this error. I'll have to
> live with it for now until I can look into it deeper. Has anyone else
> had this error?
But you shouldn't call respond yourself. That's for Wicket to do. The
only thing you should do is the the request target on the request
cycle.
Eelco
> Stanczak Group wrote:
> > Instead of "setRequestTarget(rsrt)" I use this
> > "rsrt.respond(getRequestCycle());", is that correct? It does work, but
> > I get this in the logs "08:53:03,277 ERROR WebResponse:190 - Unable to
> > redirect to: ?wicket:interface=:2::::, HTTP Response has already been
> > committed.". It works, but I wouldn't mind fixing that error, just to
> > keep things clean.
> >
> >
> > Johan Compagner wrote:
> >> or something like this:
> >>
> >> new Link()
> >> {
> >> onclick()
> >> {
> >> CharSequence discounts = DataBase.getInstance()
> >> .exportDiscounts();
> >>
> >>
> >> ResourceStreamRequestTarget rsrt = new ResourceStreamRequestTarget(new
> >> StringResourceStream(discounts, "text/csv"));
> >> rsrt.setFileName(name);
> >> setRequestTarget(rsrt)
> >> }
> >> }
> >>
> >> Maybe we should give ResourceStreanRequestTarget 1 extra constructor
> >> with
> >> the file name..
> >>
> >> setRequestTarget(new ResourceStreamRequestTarget(new
> >> StringResourceStream(discounts, "text/csv",name)))
> >>
> >>
> >> On 10/5/07, Eelco Hillenius wrote:
> >>
> >>> On 10/5/07, Eelco Hillenius wrote:
> >>>
> >>>> What do you use for the export? You probably should use a resource.
> >>>> For instance:
> >>>>
> >>>> public class DiscountsExport extends WebResource {
> >>>>
> >>>> public static class Initializer implements IInitializer {
> >>>>
> >>>> public void init(Application application) {
> >>>> SharedResources res = application.getSharedResources();
> >>>> res.add("discounts", new DiscountsExport());
> >>>> }
> >>>> }
> >>>>
> >>>> public DiscountsExport() {
> >>>>
> >>>> setCacheable(false);
> >>>> }
> >>>>
> >>>> @Override
> >>>> public IResourceStream getResourceStream() {
> >>>> CharSequence discounts = DataBase.getInstance().exportDiscounts();
> >>>> return new StringResourceStream(discounts, "text/plain");
> >>>> }
> >>>>
> >>>> @Override
> >>>> protected void setHeaders(WebResponse response) {
> >>>> super.setHeaders(response);
> >>>> response.setAttachmentHeader("discounts.csv");
> >>>> }
> >>>> }
> >>>>
> >>> Sorry, this might be easier to understand:
> >>>
> >>> WebResource export = new WebResource() {
> >>>
> >>> @Override
> >>> public IResourceStream getResourceStream() {
> >>> CharSequence discounts = DataBase.getInstance()
> >>> .exportDiscounts();
> >>> return new StringResourceStream(discounts, "text/csv");
> >>> }
> >>>
> >>> @Override
> >>> protected void setHeaders(WebResponse response) {
> >>> super.setHeaders(response);
> >>> response.setAttachmentHeader("discounts.csv");
> >>> }
> >>> };
> >>> export.setCacheable(false);
> >>>
> >>> add(new ResourceLink("exportLink", export));
> >>>
> >>>
> >>> Eelco
> >>>
> >>> ---------------------------------------------------------------------
> >>> To unsubscribe, e-mail: [EMAIL PROTECTED]
> >>> For additional commands, e-mail: [EMAIL PROTECTED]
> >>>
> >>>
> >>>
> >>
> >>
> >
>
> --
> Justin Stanczak
> Stanczak Group
> 812-735-3600
>
> "All that is necessary for the triumph of evil is that good men do nothing."
> Edmund Burke
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------
Yahoo! kullaniyor musunuz?
Istenmeyen postadan biktiniz mi? Istenmeyen postadan en iyi korunma Yahoo!
Posta'da
http://tr.mail.yahoo.com