Results 1 to 9 of 9

Thread: Equivalent of JSF's responseComplete() in Spring Webflow

  1. #1
    Join Date
    Jul 2008
    Posts
    13

    Default Equivalent of JSF's responseComplete() in Spring Webflow

    I'm just not very fluent with Spring MVC as I'm
    with JSF. In one of our organization's projects, we use Spring MVC and use
    Jasper for reproting. We allow users to download a .PDF report. In JSF,
    after writing the PDF bytes to the response stream along with
    Content-Disposition header, I invoke responseComplete() on FacesContext
    instance to tell JSF not to meddle with the reponse further.

    How do I achieve the same with Spring MVC?

    Right now we get a,
    Code:
    java.lang.IllegalStateException
            at org.apache.catalina.connector.ResponseFacade.sendRedirect(ResponseFac
    ade.java:435)

  2. #2
    Join Date
    Aug 2006
    Location
    Brooklyn
    Posts
    556

    Default

    Spring MVC has built-in support for Jasper. Have a look at the Spring reference documentation. Also one of the samples that ship with the framework demonstrate how to do this.

  3. #3
    Join Date
    Feb 2009
    Posts
    2

    Default problem in response.getOutputStream()

    I tried the same in Spring webflow. I am using Jasperreport to generate a PDF. But downloading the PDF creates a problem in this approach.

    My code snippet looks like below..

    Code :
    private void generatePdf(String path, RequestContext requestContext)
    throws IOException
    {
    ServletExternalContext servletExternalContext =
    (ServletExternalContext)requestContext.getExternal Context();
    HttpServletResponse response =
    (HttpServletResponse)servletExternalContext.getNat iveResponse();
    ....
    ....
    response.setContentType("application/pdf");
    byte[] bytes = JasperExportManager.exportReportToPdf(print);
    response.setContentType("application/pdf");
    response.setHeader("Content-disposition", "attachment; filename=\""
    + OUTPUT_FILE_NAME);
    response.setContentLength(bytes.length);
    ServletOutputStream servletOutputStream = response.getOutputStream();
    servletOutputStream.write(bytes);
    servletOutputStream.flush();
    }



    But in this way I get some error and the downloaded PDF does not open. The error which I get is like below...(I tried the same without flushing the outputStream but landed with the same.)

    11:57:28,297 ERROR [[jsp]] Servlet.service() for servlet jsp threw exception
    java.lang.IllegalStateException: getOutputStream() has already been called for t
    his response


    I think I am getting this error because Framework still tries to call getOutputStream() to complete the response. But I have no idea how can I stop that and handle the response manually. (If any handling required furthermore).

    Can anyone help me about this? I guess this problem is relevant to the problem stated above.

  4. #4
    Join Date
    Jan 2009
    Posts
    15

    Default

    Hi,

    I am doing a similar thing like this..When i am calling a method like this from my flow.xml an error is coming..
    can u please post how u r calling the method from flow

  5. #5
    Join Date
    Feb 2009
    Posts
    2

    Default

    Hi,

    There is nothing unusual in the flow according to me. I am calling using webflow:evaluate to execute. Please refer the code below for reference.

    <webflow:view-state id="view" view="view">
    <webflow:transition on="generatePdf">
    <webflow:evaluate
    expression="pdfGenerationFormAction.exportAsPdf">
    </webflow:evaluate>
    </webflow:transition>
    </webflow:view-state>

    exportAsPdf(RequestContext) is the method which calls the generatePdf() method intern.

    Any thing wrong in this part?

  6. #6
    Join Date
    Jan 2009
    Posts
    15

    Default

    Hi,

    I am also trying to call a method like this.
    But the problem is that its searching for the method as methodname not as methodname(requestContext)

    for my code details please check:
    http://forum.springframework.org/showthread.php?t=67552
    http://forum.springframework.org/showthread.php?t=67456

  7. #7
    Join Date
    Jun 2009
    Posts
    2

    Default How to prevent spring webflow from sending a redirect

    Did anyone find a solution to this problem ..since I am also having a similar problem

  8. #8
    Join Date
    Jan 2011
    Posts
    11

    Default java.lang.IllegalStateException: getOutputStream() has already been called

    Has anyone found a solution to the issue with?

    I'm also having the same problem

    java.lang.IllegalStateException: getOutputStream() has already been called for this response when trying the example with:

    Code:
    <transition on="print">
            <evaluate expression="printBoardingPassAction" />
        </transition>

  9. #9

    Default

    In the action method:

    Code:
    import org.springframework.webflow.execution.RequestContext;
    
    public print(RequestContext context) {
    
        //generate the file ... and in the end
        context.getExternalContext().recordResponseComplete();
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •