Search code examples
javajsf-2richfacesdownload

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().responseComplete();

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.


Solution

  • 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.