mjovanov wrote:
>
> We have a very simple setup for exporting data table content to excel: a
> commandLink invoking an action method that renders content type
> "application/vnd.ms-excel". However we are seeing some really funky
> behavior, specifically whenever actions other than exporting to excel are
> invoked, the exportHtmlTableToExcel action method still gets executed
> during JSF lifecycle, causing the browser to display the Download/Open
> dialog box again! Using the debugger I can see the exportHtmlTableToExcel
> getting invoked even though it should not be. It's as if the JSF state
> somehow got corrupt and/or was not properly reset from the previous cycle
> involving Exporting to Excel. Has anyone seen this before? Any suggestions
> would be greatly appreciated.
>
> code:
> <h:commandLink action="#{backingBean.exportHtmlTableToExcel}"
> class="linkCaption">
> <t:graphicImage url="images/icon_excel.gif"
> alt="#{msg.labelExportQueueSummToExcel}" width="21" height="16" />
> <h:outputText value="#{msg.labelExportToExcel}" />
> </h:commandLink>
>
> public void exportHtmlTableToExcel() throws IOException {
> String contentType = "application/vnd.ms-excel";
> FacesContext fc = FacesContext.getCurrentInstance();
> String filename = fc.getExternalContext().getUserPrincipal().getName()
> + "-" + System.currentTimeMillis()
> + ".xls";
> HttpServletResponse response = (HttpServletResponse)
> fc.getExternalContext().getResponse();
> response.setHeader("Content-disposition", "attachment; filename=" +
> filename);
> response.setContentType(contentType);
>
> StringBuffer htmlBuffer = new StringBuffer();
> ...
> [write data table content to buffer here]
> ...
> ...
> PrintWriter out = response.getWriter();
> htmlBuffer.append("<HTML>\n");
> out.print(htmlBuffer);
> out.close();
> fc.responseComplete();
> }
>
>
Looks like this issue was resolved by upgrading to the latest distribution
of MyFaces (1.2.3). If anyone knows exactly why this did the trick (was it
some type of bug fix in this release?) I would still like to know...
--
View this message in context:
http://www.nabble.com/Export-Data-Table-to-Excel---Strange-JSF-Lifecycle-Behavior-%21-tp17831096p17986137.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.