简体   繁体   English

Seam以Excel格式导出数据表

[英]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 我正在尝试使用seam并按照http://docs.jboss.org/seam/2.1.0.GA/reference/en-US/html/excel.html#excel.intro将Richdata表导出到excel

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." 它指示“要在您的应用程序中包含Microsoft®Excel®电子表格应用程序支持,请将jboss-seam-excel.jar与jxl.jar JAR文件一起包含在WEB-INF / lib目录中。”

I found below two dependencies online for the jars.. 我在网上找到了以下两个罐子的依赖关系。

War pom.xml 战争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 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.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 之前我在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 jboss-seam-excel-2.1.2.jarjxl-2.6.12.jar部署在WEB-INF / lib下

But, I did not find.. org.jboss.seam.excel.DocumentStoreServlet anywhere, so using org.jboss.seam.document.DocumentStoreServlet in web.xml 但是,我在任何地方都找不到.. org.jboss.seam.excel.DocumentStoreServlet ,因此在web.xml中使用org.jboss.seam.document.DocumentStoreServlet

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… 但是,我在登录时发现属性未找到异常,下面是完整的错误堆栈跟踪。.loginAction.stationID与我的更改无关...

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. 当我添加接缝Excel依赖项时,发生PropertyNotFoundException。

I saw this in the dependency tree.. mvn dependency:tree and found this.. 我的依赖关系树看到这个.. mvn dependency:tree ,发现这个..

[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.. excel jar附带了jboss-seam ejb和jboss-el等。我认为org.jboss.el:jboss-el已经与我项目中的一个碰撞了。..jboss-seam:ejb:2.2.0 .GA ..,尝试将以下排除项放入Maven ..中,但也可以工作。

   <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? 您正在使用哪个JBoss版本? I'm assuming JBoss 5 我假设是JBoss 5

Check this reference: https://community.jboss.org/thread/186791 检查此参考: https : //community.jboss.org/thread/186791

This is for an older version, but also helpful: 这是较旧的版本,但也有帮助:

https://community.jboss.org/thread/184757 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 您需要在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.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.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 :). 我将停止使用POI方法来导出excel :)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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