开发者

Export to XLS with JSF2 and RichFaces

I have an Application based on JSF2 and RichFaces; I have developed a process to export some data in a PDF using POI.

In my XHTML I call to a method:

<rich:modalPanel>
    ...
    <p:commandButton image="/images/excel.png" action="#{managedBean.doXLS}"         ajaxSingle="true" rendered="true" value="Exportar a XLS">
        <f:setPropertyActionListener target="#{statisticsBean.optionToExport}"     value="1"/>
    </p:commandButton>
    ...
</rich:modalPanel>

And I am calling by Java like this:

... // create XLS
response.setHeader( "Content-Disposition", "attachment; filename=\"" +       nombreFichero + ".xls\"" );
response.setContentType("application/vnd.ms-excel");

OutputStream o = response.getOutputStream();

if ( workbook!=null && o!=null)
    workbook.write(o);
o.flush();
o.close();

if (!FacesContext.getCurrentInstance().getResponseComplete())
FacesContext.getCurrentInstance().resp开发者_运维百科onseComplete();

No exception is been thrown, but nothing happen in my screen. What´s the problem?


SOLVED:

OK, after talk with @BalusC (thanks), I can´t response a file inside a "rich:modalPanel" because this one is created by ajax. NO MATHERS IF IS ajaxsingle or not.


OK, after talk with @BalusC (thanks), I can´t response a file inside a "rich:modalPanel" because this one is created by ajax. NO MATHERS IF IS ajaxsingle or not.


I did it like this:

<a4j:commandButton id="printDocument" value="Pdf link" 
  action="generatePdf" styleClass="button" oncomplete="openPdf();" rendered="/>

With OpenPDF defined as:

<script language="JavaScript">
    //<![CDATA[
        function openPdf() {
            pdfWindow = window.open('#{pdfDocument.documentLink}');
            if (window.focus) {pdfWindow.focus()};
            return false;
        }
        //]]>
    </script>

This is using Richfaces, Facelets and Spring Webflow. The action generatedPdf calls a webflow action, which calls a Java class which generates the pdf document somewhere on the disk. The pdfDocument.documentLink contains the path to a Servlet which does the usual thing with the content disposition and streams the result to the browser.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜