2010-02-23 8 views
1

Dans mon application, j'essaie d'exporter les données du <h:DataTable> dans un fichier PDF en utilisant Apache TomaHawk. Pendant le chargement de la page, je reçois une exception. J'ai collé mon code et l'exception ci-dessous.Exporter les données dans un format PDF avec Tomahawk?

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) 

Répondre

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

Soit le classpath est sale (dupliquer les fichiers JAR de différentes versions qui se sont heurtés à chaque OTH er), ou vous avez simplement oublié d'installer Tomahawk et/ou ses dépendances commons-fileupload, commons-logging, commons-io et/ou commons-el (il suffit de mettre le (s) fichier (s) JAR dans /WEB-INF/lib).

+0

avez vérifié tout ce que vous avez dit.avons suivi les étapes que vous avez mentionnées seulement. – Hariharbalaji

+0

Désolé, mais l'exception prouve le contraire. Si vous êtes seulement certain que Tomahawk est installé correctement, il y a certainement une collision de version. Nettoyez votre classpath des anciens doublons versionnés et alignez toutes les versions. Ou relisez la trace de pile pour trouver une cause ** racine ** (la partie en dessous), pour le cas où vous ne l'avez pas encore fait. – BalusC

Questions connexes