Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: Spring Web Flow + PDF Generation

  1. #1
    Join Date
    Apr 2008
    Posts
    5

    Default Spring Web Flow + PDF Generation

    Hey all! I've spent the last 3 hours trying to get a view to generate a PDF file and then send it to the client and, to put it mildly, I've had no luck at all.

    I've been searching through the forums and since the word "pdf" doesn't get included due to min. length, I didn't have much luck.

    Can anyone point me in the right direction? Or even better, guide me through it? So far I know I have to subclass AbstractPdfView and use iText, but I have no idea how to output the PDF itself.


    Thanks!

  2. #2
    Join Date
    Jul 2006
    Location
    London
    Posts
    500

    Default

    Create a report flow:
    Code:
    <view-state id="report.view" view="externalRedirect:http://.....etc/report.htm?reportViewId=userPdfView">		
      <transition to="report.end"/>
    </view-state>
    
    <end-state id="report.end" />
    Setup your MVC Stuff using

    Code:
    .
      <prop key="/report.htm">reportController</prop>
    .
    
    <bean id="reportController" class="com.abc.web.controller.ReportController">
    	<property name="methodNameResolver" ref="methodNameResolver"/>		
    </bean>
    
    <bean id="methodNameResolver"
    		class="org.springframework.web.servlet.mvc.multiaction.InternalPathMethodNameResolver" />
    		
    <bean id="viewResolver"	class="org.springframework.web.servlet.view.BeanNameViewResolver" />
    ReportController returns report view
    Code:
    public ModelAndView report(HttpServletRequest request, HttpServletResponse response) throws Exception {
      .
      return new ModelAndView(reportViewId);					}
    Report Mapping (UserPdfView extends Springs AbstractPdfView)
    Code:
    <bean id="userPdfView" class="com.abc.view.UserPdfView" />
    Hope that helps..
    Regards,
    James

  3. #3
    Join Date
    Jul 2006
    Location
    London
    Posts
    500

    Default

    See here for an example on building the pdf document:
    From Google Code Search
    Regards,
    James

  4. #4
    Join Date
    Apr 2008
    Posts
    5

    Default

    Thanks! Much appreciated.

    Does the PDF View *have* to be an end-state?

  5. #5
    Join Date
    Jul 2006
    Location
    London
    Posts
    500

    Default

    I don't follow you?

    The report.end transition just returns the flow to the parent.
    Regards,
    James

  6. #6
    Join Date
    Apr 2008
    Posts
    5

    Default

    Gotcha. Slight newbie question: I'm using the standard architecture from the phonebook sample (started from that, then modified a lot...)

    Where does the "<prop key="/report.htm">reportController</prop>" bit go? Apologies.



    B

  7. #7
    Join Date
    Jul 2006
    Location
    London
    Posts
    500

    Default

    snippet from SimpleUrlHandlerMapping
    Regards,
    James

  8. #8
    Join Date
    Apr 2008
    Posts
    5

    Default

    After adding the snippets you posted, I now have 2 viewResolvers:
    Code:
        <bean id="viewResolver" class="org.springframework.web.servlet.view.BeanNameViewResolver" />
    
        <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="prefix" value="/WEB-INF/jspx/"/>
            <property name="suffix" value=".jspx"/>
        </bean>
    What should I change?

  9. #9
    Join Date
    Mar 2008
    Posts
    21

    Default

    Thank you jamesclinton. It works fine but I have a problem with the last nightly build. I have a link in a page which opens a pdf file with indicated method (externalRedirect). The file is well opened but the flow seems reinitialized. I have to click 2 times (the page is refreshed the first time) in the other link after having clicked on pdf link.

  10. #10
    Join Date
    Mar 2008
    Posts
    21

    Default

    I have a redirection to an other flow which generates pdf (in the response) but main flow is reinitialized when I click on any link in the page. Why is the main flow reinitialized whereas the pdf is generated in other flow ?
    I have not this behavior with the 2.0.0 ci-418 version.

Posting Permissions

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