|
|
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 quot;pdfquot; 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!
Create a report flow:
Code:
lt;view-state id=quot;report.viewquot; view=quot;externalRedirect:report.htm?reportViewId=userPdfViewquot;gt; lt;transition to=quot;report.endquot;/gt;
lt;/view-stategt;
lt;end-state id=quot;report.endquot; /gt;
Setup your MVC Stuff usingCode:
. lt;prop key=quot;/report.htmquot;gt;reportControllerlt;/propgt;
.
lt;bean id=quot;reportControllerquot; class=quot;com.abc.web.controller.ReportControllerquot;gt;
lt;property name=quot;methodNameResolverquot; ref=quot;methodNameResolverquot;/gt;
lt;/beangt;
lt;bean id=quot;methodNameResolverquot;
class=quot;org..web.servlet.mvc.multiaction.InternalPathMethodNameResolverquot; /gt;
lt;bean id=quot;viewResolverquot;class=quot;org..web.servlet.view.BeanNameViewResolverquot; /gt;
ReportController returns report view
Code:
public ModelAndView report(fromServletRequest request, fromServletResponse response) throws Exception { . return new ModelAndView(reportViewId);}
Report Mapping (UserPdfView extends Springs AbstractPdfView)
Code:
lt;bean id=quot;userPdfViewquot; class=quot;com.abc.view.UserPdfViewquot; /gt;
Hope that helps..
See here for an example on building the pdf document:
From Google Code Search
Thanks! Much appreciated.
Does the PDF View *have* to be an end-state?
I don't follow you?
The report.end transition just returns the flow to the parent.
Gotcha. Slight newbie question: I'm using the standard architecture from the phonebook sample (started from that, then modified a lot...)
Where does the quot;lt;prop key=quot;/report.htmquot;gt;reportControllerlt;/propgt;quot; bit go? Apologies.
B
snippet from SimpleuclHandlerMapping
After adding the snippets you posted, I now have 2 viewResolvers:
Code:
lt;bean id=quot;viewResolverquot; class=quot;org..web.servlet.view.BeanNameViewResolverquot; /gt;
lt;bean id=quot;viewResolverquot; class=quot;org..web.servlet.view.InternalResourceViewResolverquot;gt; lt;property name=quot;prefixquot; value=quot;/WEB-INF/jspx/quot;/gt; lt;property name=quot;suffixquot; value=quot;.jspxquot;/gt; lt;/beangt;
What should I change?
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.
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. |
|