Dear SWF users,
I have trolled the forum but can't find an answer to my problem, so here it is.
Simple thing I want: In a view where the user can edit some information I also want a print button, which transforms the information into a PDF and sends it to the user for download. After that he resumes editing the information or goes back to an overview view.
I implemented this according to the spring documentation under "Streaming actions" in the SWF documentation.
The problem is though that the response which holds the PDF is followed by SWF's redirect which concludes in the behaviour that the user can't download the file, but just gets the same view presented again.
Here's part of the flow.xml:
Here's the Action code:Code:<view-state id="Details"> <transition on="save"> .... </transition> <transition on="back" to="Overview"> ... </transition> <transition on="print" > <evaluate expression="printAction"/> </transition> </view-state>
And here's the service code which holds the mark response complete call.Code:public class PrintAction extends AbstractAction { private DocumentService documentService; protected Event doExecute(RequestContext context) throws Exception { LoadDetailBean detail = (LoadDetailBean ) context.getViewScope().get("load"); documentService.sendPdf(detail.getId(), context); return success(); } public DocumentService getDocumentService() { return documentService; } public void setDocumentService(DocumentService documentService) { this.documentService = documentService; } }
The only way I got the dowload to work is to have the transition change to the flows end-state:Code:public class DocumentService { private static Logger log = Logger.getLogger(DocumentService.class); private ILoadDao loadDao = new LoadDao(); public void sendPdf(Integer loadId, RequestContext context) throws IOException, DocumentException { Validate.notNull(loadId); Validate.notNull(context); LoadPdfData loadPdfData = loadDao.getLoadPdfData(loadId); // get response HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getNativeResponse(); response.reset(); response.setCharacterEncoding("UTF-8"); response.setContentType("application/force-download"); response.setHeader("Content-Disposition","attachment; filename=\"test.pdf\""); OutputStream out = response.getOutputStream(); ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); this.createPdf(loadPdfData , byteOut); response.setContentLength(byteOut.size()); byteOut.writeTo(out); out.flush(); // mark response complete context.getExternalContext().recordResponseComplete(); } private void createPdf(AnnexVIIData annexVIIData, OutputStream out) throws IOException, DocumentException { [...] } }
But this is no option since the user should be able to continue editing information on the Detail view or go back to the Overview view and continue working.Code:<view-state id="Details"> <transition on="save"> .... </transition> <transition on="back" to="Overview"> ... </transition> <transition on="print" to="finish"> <evaluate expression="printAction"/> </transition> </view-state> <end-state id="finish"/>
Can you please help me out? How do I tell SWF to not redirect on this transition?
cheers
remraf


Reply With Quote
