[Ajax4JSF] JSF导出文件异常getOutputStream() has already been called
freesky_zh
2009-04-23
for this case, I have a compromise solution, that is, call servlet in webflow, then export pdf in servlet.
the sevlet is independant on Webflow and JSF, so the getWriter() mothod won't be called by the container. the solution is like below ======================================== listView.xhtml ======================================== <tr:commandLink action="exportPdf"> <tr:image source="../images/pdf.jpg" shortDesc="Export to PDF"/> </tr:commandLink> =============================================== webflow.xml =============================================== <view-state id="listView"> ... <transition on="exportPdf" to="pdfView" > <evaluate expression="backingBean.saveTable()" /> </transition> </view-state> ... <view-state id="pdfView" view="externalRedirect:contextRelative:/exportPdfAction" > <transition to="txnHistoryListView" /> </view-state> ================================================ in the saveTable() method of backingbean, we can put tabel value and related value into HTTPSession like this. =========================================== backingbean.java =========================================== RequestAttributes attributes = RequestContextHolder.currentRequestAttributes(); attributes.setAttribute("key", tableValue, RequestAttributes.SCOPE_SESSION); ================================================= "externalRedirect:contextRelative:/exportPdfAction" configured in webflow.xml will navigator to the servlet configured in web.xml in servlet, we can get data from session and invoke method to export pdf file. you should pay attention to one thing, that is, you can't pass UIXTable object into the session. Because out of JSF lifecycle, we can't get label value from the UIXTable object. I guess this is related to the FacesContext issue. so you should wrap the data in UIXTable into your own object and save it into session. |