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");
}
}
Eelco
On 10/4/07, Stanczak Group <[EMAIL PROTECTED]> wrote:
> This works:
>
> getWebRequestCycle().getWebResponse().setContentType("text/csv");
>
> getWebRequestCycle().getWebResponse().setHeader("Content-Disposition",
> "attachment;filename=\"export_" +
> formatFile.format(Calendar.getInstance().getTime()) + ".csv\"");
> OutputStream cout =
> getWebRequestCycle().getWebResponse().getOutputStream();
> cout.write(out.toString().getBytes());
> cout.flush();
> cout.close();
>
> But I get this in the logs. How can I do this better?
>
> 16:31:45,391 ERROR WebResponse:190 - Unable to redirect to:
> ?wicket:interface=:2::::, HTTP Response has already been committed.
>
>
> Stanczak Group wrote:
> > This maybe? Should I be using "getWebRequestCycle().getWebResponse()"
> > instead of "getResponse()."?
> > getWebRequestCycle().getWebResponse().setHeader()
> >
> > Stanczak Group wrote:
> >> How can I do this in Wicket? I'm writing a csv generated file to the
> >> output, but I don't know how to tell the client what file name to
> >> use. This is what I was using before, is there another way?
> >>
> >> getResponse().setHeader("Content-Disposition",
> >> "attachment;filename=\"export_" +
> >> formatFile.format(Calendar.getInstance().getTime()) + ".csv\"");
> >>
> >> ############################Code##############################################
> >>
> >> getResponse().setContentType("text/csv");
> >>
> >> getResponse().setHeader("Content-Disposition",
> >> "attachment;filename=\"export_" +
> >> formatFile.format(Calendar.getInstance().getTime()) + ".csv\"");
> >> OutputStream cout =
> >> getResponse().getOutputStream();
> >> cout.write(out.toString().getBytes());
> >> cout.flush();
> >> cout.close();
> >>
> >
>
> --
> 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]