You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by "CONNER, BRENDAN (SBCSI)" <bc...@sbc.com> on 2005/12/01 17:25:11 UTC

Curious problem with exporting data

Our application has a requirement to export certain data as a
comma-delimited file to the user.  To do this, our action class does the
following:

response.setContentType("text/html");
response.setHeader("Content-Disposition", "attachment;filename=\"" +
defaultFileName + "\"");
PrintWriter out = response.getWriter();
...
out.println(data); // in a loop to output all the rows
...
facesContext.getApplication().getStateManager().saveSerializedView(faces
Context);
facesContext.responseComplete();
return null;

The above works fine in that, when the action is invoked, the user gets
the typical "file download" pop-up (with the options: open, save,
cancel, or more info).  The pop-up gets displayed with following
checkbox checked and disabled: "Always ask before opening this type of
file."

The problem is that, if I press the "open" button, the same dialog
re-appears, but this time, the checkbox is enabled.  Only after I hit
"open" again can I actually see the data.  By contrast, if I hit the
"save" button, I only have to do that once.

Can anyone explain to me why I have to hit the "open" button twice on
the "file download" pop-up, given the code I've listed above?

- Brendan