I think partialSubmit must be false on the parent component (the one
that contains the listener)
-M
On Nov 9, 2007 1:15 PM, Oscar Reitsma <[EMAIL PROTECTED]> wrote:
> Good Day,
>
> I am having an issue downloading a file depending on parameters inputted on
> a dialog. Perhaps someone could point me in the right direction
>
> Basically required functionality is as follows:
> - A user clicks on a link to generate a report.
> - A dialog pops up where the user can input parameters for the report.
> - The user clicks the OK button
> - The report is generated, and sent to the user as a file download.
>
> Versions:
> MyFaces v1.1.5
> Trinidad v1.0.3
> Jetty 6.1.5
> Firefox: 2.0.0.9 / IE 6.0
>
> I've tried a few ways of doing this.
> 1. Attempt the generation and download in the dialogs return method. This
> causes an invalid PPR response (as seen using FireBug)
>
> public void handleDialogReturn(ReturnEvent evt) {
> FacesContext context = FacesContext.getCurrentInstance();
>
> HttpServletResponse response =
> ( HttpServletResponse ) context.getExternalContext ().getResponse();
>
> OutputStream out = null;
> InputStream in = null;
> try
> {
> in = getService().generateReport(
> selectedReport, getSelectedMonth(), getSelectedYear(),
> getReportType());
>
> if (in != null) {
>
> response.setContentType(getReportContentType()); // i.e.
> "application/vnd.ms-excel"
> response.setHeader("Content-Disposition",
> "attachment;filename=\""
> + selectedReport.getFilename() ");
>
> out = response.getOutputStream();
>
> int read = -1;
> byte[] buffer = new byte[1024];
>
> while ((read = in.read(buffer, 0, buffer.length)) != -1) {
> out.write(buffer, 0, read);
> }
>
> out.flush();
> }
> }
> catch (IOException ex) {
>
> }
> finally
> {
> try
> {
> out.close();
> }
> catch (Exception ex) {}
> try
> {
> in.close();
> }
> catch (Exception ex) {}
> }
> context.responseComplete();
> }
>
> 2. Try to do the same thing in the actionListener method of the dialog's
> commandButton. The download here works, however, when calling the
> returnFromDialog method, I get the following exception and the dialog
> remains in view:
>
> Caused by: java.lang.IllegalStateException: STREAM
> at org.mortbay.jetty.Response
> .getWriter(Response.java:583)
> at
> javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:122)
> at
> org.apache.myfaces.trinidadinternal.renderkit.core.CoreRenderKit._getHtmlWriter(CoreRenderKit.java:744)
> at
> org.apache.myfaces.trinidadinternal.renderkit.core.CoreRenderKit.returnFromDialog
> (CoreRenderKit.java:282)
> at
> org.apache.myfaces.trinidadinternal.context.DialogServiceImpl.returnFromDialog(DialogServiceImpl.java:173)
> at
> org.apache.myfaces.trinidadinternal.context.RequestContextImpl.returnFromDialog
> (RequestContextImpl.java:122)
>
>
> Any comments/suggestions would be highly appreciated,
>
> thanks,
> Oscar
--
Matthias Wessendorf
further stuff:
blog: http://matthiaswessendorf.wordpress.com/
mail: matzew-at-apache-dot-org