3 Replies Latest reply on Jan 3, 2011 12:56 PM by cobar

    a4j:commandButton and Apache POI

    cobar

      I know this is a little out of place but I was wondering if anyone has used Apache POI with an ajax event component, a4j:commandButton or a4j:commandLink.

       

      Issue: All is fine using h:commandButton. However, I wanted to use a rich:modalPanel while the Excel workbook was being created. So I used

       

      {code}

      <a4j:region id="rptExport" renderRegionOnly="true">
             <a4j:commandButton id="rptExportBtn" immediate="false"
                                             onclick="Richfaces.showModalPanel('exportModalPanel')"
                                             oncomplete="Richfaces.hideModalPanel('exportModalPanel')"
                                             actionListener="#{OptimizationToolManagedBean.exportNonOptimalRoutesToExcel}"
                                             value="Export">
              </a4j:commandButton>
              <rich:modalPanel id="exportModalPanel" autosized="true">
                    <h:panelGrid id="exportPanel" columns="2" style="text-align:center;">
                          <h:outputLabel id="exportText" value="Exporting" styleClass="fieldLabel"/>
                               <h:graphicImage id="eportImg" value="/images/indicator.gif"/>
                     </h:panelGrid>
             </rich:modalPanel>
      </a4j:region>

      {code}

       

      The actionListener is fired, the modal panel is displayed but the Excel app is not launched and the modal panel never goes away as if oncomplete never happens. I suspect it has to do with FacesContext fc.responseComplete();

        • 1. Re: a4j:commandButton and Apache POI
          ilya40umov

          I'm afraid this is not possible. Because when you use h:commandButton you send some specital headers with response and that's why browser opens your resonse as a workbook in Excel. But you can't possibly open a workbook inside your html page. I think you have only one option you should use some JS components which look like Excel. See http://www.treegrid.com/treegrid/www/ for example. I'm sorry if I disappointed you.

           

          P.S. May be folks have other opinions.

          1 of 1 people found this helpful
          • 2. Re: a4j:commandButton and Apache POI
            ilya_shaikovsky

            Ilya is right, you can't use ajax controls to initiate downloads, excel's PDF's and so on passing to client. So you have to use h:commandButton and probably trigger some indication using its onclick.

            • 3. Re: a4j:commandButton and Apache POI
              cobar

              Many thanks for looking at this! I travelled down the alternate road   by triggering a modal panel using an a4j:support because the   h:commandButton does not support oncomplete. The problem is the response   never triggers the oncomplete, probably because the export action   forced the reponse complete. The best solution I came up with is to   allow the user to close the modal panel manually which means they can   start firing other events before the export is complete which is what I   was hoping to prevent. Que sera sera

               

              Thanks for the help.