David,

Thanks for the hint. Though I didn't ask the question, I have seen this behavior on one or two of my pages. Now I'll have a chance to fix it perhaps.

Hmm... I went to the link your code points to, but there was really no mention of *why* this solution works. Do you know who originally figured this out or why it is necessary? I assume it's because we are skipping some necessary lifecycle phase when we write to the out and then call responseComplete?

Regards,

Jeff Bischoff
Kenneth L Kurz & Associates, Inc.

David Chandler wrote:
Simply add these two lines of code before the call to responseComplete():

// Save serialized view or else after clicking on the export button,
user will have to click TWICE to invoke another action
        // See http://swforum.sun.com/jive/thread.jspa?threadID=63566
        StateManager stateManager = (StateManager) facesContext
                .getApplication().getStateManager();
        stateManager.saveSerializedView(facesContext);

/dmc

On 12/29/06, ::SammyRulez:: <[EMAIL PROTECTED]> wrote:
Hello and happy new year

Im' using this action method to generate dynamicaly pdf file and send
them to the browser

  public String generaContratto(){
FacesContext facesContext = FacesContext.getCurrentInstance();
        HttpServletResponse response = (HttpServletResponse)
facesContext.getExternalContext().getResponse();
        response.setContentType("application/pdf");
        String fileName = "blabla.pdf";
        response.setHeader("Content-disposition", " attachment;
filename=\"" + fileName + "\"");
        try {
            ServletOutputStream out;
            out = response.getOutputStream();
            ProxyDaoFactory daoFactory = new ProxyDaoFactory();
            DocumentBuilder builder = new
DocumentBuilderWrapper(daoFactory,
facesContext.getExternalContext().getInitParameter("fileValut"));
            builder.write(offerta,out);

        } catch (Exception e) {
...
return "ERROR"
}
facesContext.responseComplete();

        return "OK";
    }

Everithing works fine: the pdf is generated, downloaded etc.

But if I trigger some other action on the same view it just render the
page again.. I think it does render response phase. Model is not
updated. It act as if navigation (the ugly back button!) button where
used.

Any ideas?

--
::SammyRulez::
http://www.kyub.com/blog/
-----------------------------------------------------------------
La programmazione รจ per un terzo interpretazione e per due terzi ispirazione.
 E per un terzo mistificazione





Reply via email to