4 Replies Latest reply on Jun 25, 2009 9:52 PM by luxspes

    strange behaviour of excel export on IE

    jmiguel77
      Hi

      I have to generate an excel file, but i had to do it "by hand" (i had some limitations using the excel exporter). After generating the file with POI i wanted to export it.

      This is the piece of code i use to it:
           private void redirectExport(final HSSFWorkbook workbook) {
                String viewId = Pages.getViewId(FacesContext.getCurrentInstance());
                String baseName = baseNameForViewId(viewId);
                DocumentType documentType = new DocumentData.DocumentType("xls", "application/vnd.ms-excel");
                DocumentData documentData = new DocumentData(baseName, documentType, workbook.getBytes());
                String id = DocumentStore.instance().newId();
                String url = DocumentStore.instance().preferredUrlForContent(baseName, documentType.getExtension(), id);
                url = Manager.instance().encodeConversationId(url, viewId);
                DocumentStore.instance().saveData(id, documentData);
                try {
                     FacesContext.getCurrentInstance().getExternalContext().redirect(url);
                } catch (IOException e) {
                     throw new ExcelExporterException(Interpolator.instance().interpolate("Could not redirect to #0", url), e);
                }
           }

      As you can see, the method gets the created workbook and then redirects it to the user for opening/downloading.

      Using firefox/openoffice, it works great, the file can be opened or downloaded just fine. But using internet explorer/excel, the file cannot be opened. When i hit the open button in ie, it gives me this message:

      "The file you are trying to open, 'seam-docstore.seam', has a different format than the specified by the file extension. ...(bla, bla, bla). Would you like to open? "

      If i click yes or no, then it throws an error saying that the service / connection, is not available ??

      Any thoughts ?? thanks a lot
        • 1. Re: strange behaviour of excel export on IE
          nickarls

          Try using extensions filter so you get a .xls dl-link

          • 2. Re: strange behaviour of excel export on IE
            jmiguel77

            Hi, thanks for the response


            Ok, an improvement. Now i get the filename.xls link not the seam-docstore.seam one, but when i try to open the file, i get the same connection error


            any other ideas ???

            • 3. Re: strange behaviour of excel export on IE
              jmiguel77
              this is what i did, by the way:

              web.xml:

                      <servlet>
                              <servlet-name>Document Store Servlet</servlet-name>
                              <servlet-class>org.jboss.seam.document.DocumentStoreServlet</servlet-class>
                      </servlet>

                      <servlet-mapping>
                              <servlet-name>Document Store Servlet</servlet-name>
                              <url-pattern>*.xls</url-pattern>
                      </servlet-mapping>

                      <context-param>
                              <param-name>webAppRootKey</param-name>
                              <param-value>seam-excel</param-value>
                      </context-param>

              components.xml:

              <components xmlns:document="http://jboss.com/products/seam/document"
                      xsi:schemaLocation="http://jboss.com/products/seam/excel http://jboss.com/products/seam/excel/excel-2.1.xsd http://jboss.com/products/seam/document http://jboss.com/products/seam/document-2.1.xsd">

              <document:document-store use-extensions="true"/>

              jboss-web.xml:

              <class-loading java2ClassLoadingCompliance="false">
                              <loader-repository>
                                      seam.jboss.org:loader=seam-excel
                                      <loader-repository-config>java2ParentDelegation=false</loader-repository-config>
                              </loader-repository>
                      </class-loading>

              also, in the server/instance/lib, added: jboss-seam-excel.jar. jxl.jar

              thanks
              • 4. Re: strange behaviour of excel export on IE

                When I have that kind of problem I use Fiddler to inspect the response and see if there is something wrong with it (for example by comparing it with the response of a system that is returning the excel files properly).