简体   繁体   中英

Seam Export Datatable in Excel format

I am trying to export a richdata table to excel using seam, and following http://docs.jboss.org/seam/2.1.0.GA/reference/en-US/html/excel.html#excel.intro

It instructs " To include the Microsoft® Excel® spreadsheet application support in your application, included jboss-seam-excel.jar in your WEB-INF/libdirectory along with the jxl.jar JAR file."

I found below two dependencies online for the jars..

War pom.xml

<dependency>
    <groupId>org.jboss.seam</groupId>
    <artifactId>jboss-seam-excel</artifactId>
    <version>2.2.0.GA</version>
</dependency>
<dependency>
    <groupId>net.sourceforge.jexcelapi</groupId>
    <artifactId>jxl</artifactId>
    <version>2.6.12</version>
</dependency>

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:excel="http://jboss.com/products/seam/excel"
        xmlns:document="http://jboss.com/products/seam/document"

         http://jboss.com/products/seam/excel http://jboss.com/products/seam/excel-2.1.xsd
         http://jboss.com/products/seam/document http://jboss.com/products/seam/document-2.1.xsd">

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

Earlier I was also having the below in components.xml

<excel:excelFactory>
   <property name="implementations">
      <key>myExcelExporter</key>
      <value>my.excel.exporter.ExcelExport</value>
   </property>
</excel:excelFactory>

This was causing deployment exception, also no one mentioned it in their code, I got rid of this and the deployment exception.

jboss-seam-excel-2.1.2.jar and jxl-2.6.12.jar are deployed under WEB-INF/lib

But, I did not find.. org.jboss.seam.excel.DocumentStoreServlet anywhere, so using org.jboss.seam.document.DocumentStoreServlet in web.xml

However, I am getting property not found exception right at the time of login, below is the complete error stack trace.. loginAction.stationID has nothing to do with my changes…

17:04:24,934 |WARNING|  [lifecycle:81] /login.xhtml @52,138 value="#{loginAction.stationID}": Target Unreachable, identifier 'loginAction' resolved to null |||| 
javax.el.PropertyNotFoundException: /login.xhtml @52,138 value="#{loginAction.stationID}": Target Unreachable, identifier 'loginAction' resolved to null
    at com.sun.facelets.el.TagValueExpression.getType(TagValueExpression.java:62)
    at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getConvertedValue(HtmlBasicInputRenderer.java:92)
    at javax.faces.component.UIInput.getConvertedValue(UIInput.java:942)
    at javax.faces.component.UIInput.validate(UIInput.java:868)
    at javax.faces.component.UIInput.executeValidate(UIInput.java:1072)
    at javax.faces.component.UIInput.processValidators(UIInput.java:672)
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1058)
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1058)
    at javax.faces.component.UIForm.processValidators(UIForm.java:235)
    at javax.faces.component.UIComponentBase.processValidators(UIComponentBase.java:1058)
    at org.ajax4jsf.component.AjaxViewRoot$3.invokeContextCallback(AjaxViewRoot.java:439)
    at org.ajax4jsf.component.AjaxViewRoot.processPhase(AjaxViewRoot.java:238)
    at org.ajax4jsf.component.AjaxViewRoot.processValidators(AjaxViewRoot.java:455)
    at com.sun.faces.lifecycle.ProcessValidationsPhase.execute(ProcessValidationsPhase.java:76)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:510)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.billmelater.csa.filters.NewSessionFilter.doFilter(NewSessionFilter.java:89)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at com.billmelater.csa.filters.Perf4JFilter.doFilter(Perf4JFilter.java:53)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
    at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
    at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
    at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
    at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
    at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
    at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
    at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
    at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
    at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
    at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
    at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:368)
    at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:495)
    at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
    at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
    at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60)
    at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
    at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
    at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
    at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
    at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
    at java.lang.Thread.run(Thread.java:680)
17:04:24,942 |SEVERE|  [lifecycle:104] JSF1054: (Phase ID: PROCESS_VALIDATIONS 3, View ID: /login.xhtml) Exception thrown during phase execution: javax.faces.event.PhaseEvent[source=com.sun.faces.lifecycle.LifecycleImpl@42a46d79] |||| 

Deployment Exception : Could not create Component: org.jboss.seam.excel.excelFactory
**Could not create Component: org.jboss.seam.excel.excelFactory** 

PropertyNotFoundException happens when I add seam excel dependency.

I saw this in the dependency tree.. mvn dependency:tree and found this..

[INFO] +- org.jboss.seam:jboss-seam-excel:jar:2.2.0.GA:compile
[INFO] |  \- org.jboss.seam:jboss-seam:ejb:2.2.0.GA:compile
[INFO] |     +- xstream:xstream:jar:1.1.3:compile
[INFO] |     +- xpp3:xpp3_min:jar:1.1.3.4.O:compile
[INFO] |     \- org.jboss.el:jboss-el:jar:1.0_02.CR4:compile
[INFO] +- net.sourceforge.jexcelapi:jxl:jar:2.6.12:compile`

The excel jar comes with jboss-seam ejb and jboss-el etc.. I think org.jboss.el:jboss-el is colliding with the one in my project already.. also.. jboss-seam:ejb:2.2.0.GA.., tried putting the below exclusion in maven.. but dint work either..

   <dependency>
        <groupId>org.jboss.seam</groupId>
        <artifactId>jboss-seam-excel</artifactId>
        <version>2.2.0.GA</version>
        <exclusions>
            <exclusion>
                <groupId>ejb</groupId>
                <artifactId>ejb</artifactId>
            </exclusion>
            <exclusion>
                <groupId>javax.el</groupId>
                <artifactId>el-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

Which JBoss version are you using? I'm assuming JBoss 5

Check this reference: https://community.jboss.org/thread/186791

This is for an older version, but also helpful:

https://community.jboss.org/thread/184757

I cut and pasted the code below since I don't have access to code right now, but if it's not right it will be close. You'll need a reference in web.xml

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


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


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

jboss-web.xml

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

and components.xml

<components xmlns:excel="http://jboss.com/products/seam/excel"
xmlns:document="http://jboss.com/products/seam/document"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://jboss.com/products/seam/document http://jboss.com/products/seam/document-2.1.xsd
http://jboss.com/products/seam/excel http://jboss.com/products/seam/excel-2.1.xsd">

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

</components>

As I thought, I was not excluding dependencies properly, and the were colliding with other dependencies.

Here is the right version...

<dependency>
    <groupId>org.jboss.seam</groupId>
    <artifactId>jboss-seam-excel</artifactId>
    <version>2.2.0.GA</version>
    <exclusions>
        <exclusion>
            <groupId>org.jboss.seam</groupId>
            <artifactId>jboss-seam</artifactId>
         </exclusion>
        <exclusion>
             <groupId>org.jboss.el</groupId>
             <artifactId>jboss-el</artifactId>
          </exclusion>
    </exclusions>
</dependency>

Hope this helps others in future. I must say this feature is very poorly documented and one must go to several forums to know what exactly is needed. I will stop working on the POI approach to export excel :).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM