使用 Tomahawk 将数据导出为 PDF 格式?

发布于 2024-08-22 19:14:52 字数 4718 浏览 9 评论 0 原文

在我的应用程序中,我尝试使用 Apache TomaHawk 将数据从 导出到 PDF 文件中。加载页面时我遇到异常。我已经粘贴了我的代码和下面的异常。

JSF 代码

<%@ page session="false" contentType="text/html;charset=utf-8"%> 
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%> 
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%>
<%@ taglib uri="http://myfaces.apache.org/sandbox" prefix="s"%>
<f:view>
<html>
    <body>
        <h:form>
            <p>
                This component allows to export the datatable contents to an excel
                or pdf file.
            </p>

            <br>
            <t:dataTable id="tbl_cars" var="car" value="#{exBean.list}"
                preserveDataModel="false">
                <t:column>
                    <f:facet name="header">
                        <h:outputText value="Id" />
                    </f:facet>
                    <h:outputText value="#{car.id}" />
                </t:column>

                <t:column>
                    <f:facet name="header">
                        <h:outputText value="Type" />
                    </f:facet>
                    <h:outputText value="#{car.type}" />
                </t:column>

                <t:column>
                    <f:facet name="header">
                        <h:outputText value="Color" />
                    </f:facet>
                    <h:outputText value="#{car.color}" />
                </t:column>

            </t:dataTable>
            <h:commandButton action="" value="Export as excel">
                <s:exporterActionListener for="tbl_cars" fileType="XLS" />
            </h:commandButton>

            <br>

            <h:commandButton action="" value="Export as pdf">
                <s:exporterActionListener for="tbl_cars" fileType="PDF" />
            </h:commandButton>


        </h:form>

    </body>

</html> 
    </f:view>

异常

java.lang.NoClassDefFoundError: Could not initialize class    org.apache.myfaces.shared_tomahawk.config.MyfacesConfig
at org.apache.myfaces.renderkit.html.util.ExtensionsPhaseListener.writeCodeBeforeBodyEnd(ExtensionsPhaseListener.java:130)
at org.apache.myfaces.renderkit.html.util.ExtensionsPhaseListener.getCodeBeforeBodyEnd(ExtensionsPhaseListener.java:104)
at org.apache.myfaces.renderkit.html.util.ExtensionsPhaseListener.getJavaScriptCodeAndStoreInRequest(ExtensionsPhaseListener.java:94)
at org.apache.myfaces.renderkit.html.util.ExtensionsPhaseListener.afterPhase(ExtensionsPhaseListener.java:70)
at org.apache.myfaces.lifecycle.PhaseListenerManager.informPhaseListenersAfter(PhaseListenerManager.java:92)
at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:142)
at org.apache.myfaces.custom.ppr.PPRLifecycleWrapper.render(PPRLifecycleWrapper.java:84)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:182)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
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:388)
at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
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:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
at java.lang.Thread.run(Thread.java:619)

In my application I am trying to export the data from the <h:DataTable> into a PDF file using Apache TomaHawk. While loading the page I am getting an exception. I have Pasted my code and the exception below.

JSF Code

<%@ page session="false" contentType="text/html;charset=utf-8"%> 
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%> 
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%>
<%@ taglib uri="http://myfaces.apache.org/sandbox" prefix="s"%>
<f:view>
<html>
    <body>
        <h:form>
            <p>
                This component allows to export the datatable contents to an excel
                or pdf file.
            </p>

            <br>
            <t:dataTable id="tbl_cars" var="car" value="#{exBean.list}"
                preserveDataModel="false">
                <t:column>
                    <f:facet name="header">
                        <h:outputText value="Id" />
                    </f:facet>
                    <h:outputText value="#{car.id}" />
                </t:column>

                <t:column>
                    <f:facet name="header">
                        <h:outputText value="Type" />
                    </f:facet>
                    <h:outputText value="#{car.type}" />
                </t:column>

                <t:column>
                    <f:facet name="header">
                        <h:outputText value="Color" />
                    </f:facet>
                    <h:outputText value="#{car.color}" />
                </t:column>

            </t:dataTable>
            <h:commandButton action="" value="Export as excel">
                <s:exporterActionListener for="tbl_cars" fileType="XLS" />
            </h:commandButton>

            <br>

            <h:commandButton action="" value="Export as pdf">
                <s:exporterActionListener for="tbl_cars" fileType="PDF" />
            </h:commandButton>


        </h:form>

    </body>

</html> 
    </f:view>

Exception

java.lang.NoClassDefFoundError: Could not initialize class    org.apache.myfaces.shared_tomahawk.config.MyfacesConfig
at org.apache.myfaces.renderkit.html.util.ExtensionsPhaseListener.writeCodeBeforeBodyEnd(ExtensionsPhaseListener.java:130)
at org.apache.myfaces.renderkit.html.util.ExtensionsPhaseListener.getCodeBeforeBodyEnd(ExtensionsPhaseListener.java:104)
at org.apache.myfaces.renderkit.html.util.ExtensionsPhaseListener.getJavaScriptCodeAndStoreInRequest(ExtensionsPhaseListener.java:94)
at org.apache.myfaces.renderkit.html.util.ExtensionsPhaseListener.afterPhase(ExtensionsPhaseListener.java:70)
at org.apache.myfaces.lifecycle.PhaseListenerManager.informPhaseListenersAfter(PhaseListenerManager.java:92)
at org.apache.myfaces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:142)
at org.apache.myfaces.custom.ppr.PPRLifecycleWrapper.render(PPRLifecycleWrapper.java:84)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:182)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
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:388)
at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
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:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:849)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:454)
at java.lang.Thread.run(Thread.java:619)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怀里藏娇 2024-08-29 19:14:52
java.lang.NoClassDefFoundError:无法初始化类
   org.apache.myfaces.shared_tomahawk.config.MyfacesConfig

类路径不干净(不同版本的重复 JAR 文件相互冲突),或者您只是忘记安装 Tomahawk 和/或其依赖项 commons-fileupload, commons-loggingcommons-io 和/或 commons-el (只需放置 JAR 文件)在 /WEB-INF/lib 中)。

java.lang.NoClassDefFoundError: Could not initialize class
   org.apache.myfaces.shared_tomahawk.config.MyfacesConfig

Either the classpath is dirty (duplicate JAR files of different versions which get collided with each other), or you simply forgot to install Tomahawk and/or its dependencies commons-fileupload, commons-logging, commons-io and/or commons-el (just put JAR file(s) in /WEB-INF/lib).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文