2 Replies Latest reply on Oct 13, 2009 6:59 PM by cleiton alan schultz herrmann

    JasperReports with JBoss seam

    cleiton alan  schultz herrmann Newbie

      Hi.


      I'm using jboss-4.2.3.GA and jboss-seam-2.2.0.GA, and to create my reports, i'm using jasperreports-3.6.0 and ireport-nb.3.6.0. I created a very simple report, wich don't have parameters, only one static field, then I created a desktop application to test, and it works. And then I created a xhtml file into the itext example of jboss seam, that calls an seam action to generate the report, below is my code.


      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml"
            xmlns:h="http://java.sun.com/jsf/html"
            xmlns:f="http://java.sun.com/jsf/core"
            xmlns:ui="http://java.sun.com/jsf/facelets"
            xmlns:s="http://jboss.com/products/seam/taglib">
           
           <head>
                <title>Generate Report</title>
           </head>
           <body>
                <h1>Generate report</h1>
                <ul>
                     <s:button id="report" value="Generate" action="#{reportAction.create}"/>
                </ul>
           </body>
      </html>



      and below is my seam action


      package org.jboss.seam.example.pdf;
      
      import java.io.ByteArrayOutputStream;
      import java.io.File;
      import java.net.URL;
      import java.util.HashMap;
      import java.util.List;
      
      import javax.faces.context.FacesContext;
      import javax.servlet.ServletContext;
      import javax.servlet.ServletOutputStream;
      import javax.servlet.http.HttpServletResponse;
      
      import net.sf.jasperreports.engine.JREmptyDataSource;
      import net.sf.jasperreports.engine.JasperExportManager;
      import net.sf.jasperreports.engine.JasperFillManager;
      import net.sf.jasperreports.engine.JasperPrint;
      import net.sf.jasperreports.view.JasperViewer;
      
      import org.jboss.seam.ScopeType;
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.annotations.Logger;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Scope;
      import org.jboss.seam.annotations.datamodel.DataModel;
      import org.jboss.seam.international.StatusMessages;
      import org.jboss.seam.log.Log;
      
      @Name("reportAction")
      @Scope(ScopeType.SESSION)
      public class ReportAction {
      
          @Logger private Log log;
      
          @In StatusMessages statusMessages;
          
          @DataModel
          private List<String> l;
          
          public void create() {
              try {
                   ServletContext servletContext = (ServletContext)FacesContext.getCurrentInstance().getExternalContext().getContext();
                   System.out.println(servletContext.getRealPath("/WEB-INF/reports/ReportTest.jasper").replace("./", ""));
                   
                   HashMap parameters = new HashMap();
                   
                      JasperPrint jasperPrint = JasperFillManager.fillReport(servletContext.getRealPath("/WEB-INF/reports/ReportTest.jasper").replace("./", ""), parameters, new JREmptyDataSource());
                  
                   ByteArrayOutputStream output = new ByteArrayOutputStream();
                      JasperExportManager.exportReportToPdfStream(jasperPrint, output);
                     
                HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
                       response.setContentType("application/pdf");
                response.addHeader("Content-Disposition","attachment;filename=RankReport.pdf");
                response.setContentLength(output.size()/*bytes.length*/);
                ServletOutputStream servletOutputStream = response.getOutputStream();
                servletOutputStream.write(output.toByteArray(), 0, output.size()/*bytes, 0, bytes.length*/);
                servletOutputStream.flush();
                servletOutputStream.close();
                FacesContext.getCurrentInstance().responseComplete();
           } catch (Exception jre) {
                jre.printStackTrace();
           }
          }
      }
      


      but the fillReport command returns an exception


      net.sf.jasperreports.engine.JRException: Error loading object from file : /home/cleitonash/java/jboss-4.2.3.GA/server/default/tmp/deploy/tmp1866210135615017893jboss-seam-itext.ear-contents/jboss-seam-itext-exp.war/WEB-INF/reports/ReportTest.jasper



      the structure of my .ear file is:
      -lib
      -META-INF
      jboss-seam.jar
      jboss-seam-itext.jar
      jboss-seam-itext.war
      pdf.keystore


      into the lib package, I put the jasperreports-3.6.0.jar, it already had the commons jars and itext.jar.
      I put ReportTest.jasper into the .war file, in the reports package that is into the WEB-INF.


      anyone know where I'm wrong ? Is something missing ? I don't know where I can't access the file.


      Thanks.

        • 1. Re: JasperReports with JBoss seam
          cleiton alan  schultz herrmann Newbie

          cleiton alan  schultz herrmann wrote on Oct 13, 2009 16:32:


          Hi.

          I'm using jboss-4.2.3.GA and jboss-seam-2.2.0.GA, and to create my reports, i'm using jasperreports-3.6.0 and ireport-nb.3.6.0. I created a very simple report, wich don't have parameters, only one static field, then I created a desktop application to test, and it works. And then I created a xhtml file into the itext example of jboss seam, that calls an seam action to generate the report, below is my code.

          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
          <html xmlns="http://www.w3.org/1999/xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:s="http://jboss.com/products/seam/taglib">
               
               <head>
                    <title>Generate Report</title>
               </head>
               <body>
                    <h1>Generate report</h1>
                    <ul>
                         <s:button id="report" value="Generate" action="#{reportAction.create}"/>
                    </ul>
               </body>
          </html>



          and below is my seam action

          package org.jboss.seam.example.pdf;
          
          import java.io.ByteArrayOutputStream;
          import java.io.File;
          import java.net.URL;
          import java.util.HashMap;
          import java.util.List;
          
          import javax.faces.context.FacesContext;
          import javax.servlet.ServletContext;
          import javax.servlet.ServletOutputStream;
          import javax.servlet.http.HttpServletResponse;
          
          import net.sf.jasperreports.engine.JREmptyDataSource;
          import net.sf.jasperreports.engine.JasperExportManager;
          import net.sf.jasperreports.engine.JasperFillManager;
          import net.sf.jasperreports.engine.JasperPrint;
          import net.sf.jasperreports.view.JasperViewer;
          
          import org.jboss.seam.ScopeType;
          import org.jboss.seam.annotations.In;
          import org.jboss.seam.annotations.Logger;
          import org.jboss.seam.annotations.Name;
          import org.jboss.seam.annotations.Scope;
          import org.jboss.seam.annotations.datamodel.DataModel;
          import org.jboss.seam.international.StatusMessages;
          import org.jboss.seam.log.Log;
          
          @Name("reportAction")
          @Scope(ScopeType.SESSION)
          public class ReportAction {
          
              @Logger private Log log;
          
              @In StatusMessages statusMessages;
              
              @DataModel
              private List<String> l;
              
              public void create() {
                  try {
                       ServletContext servletContext = (ServletContext)FacesContext.getCurrentInstance().getExternalContext().getContext();
                       System.out.println(servletContext.getRealPath("/WEB-INF/reports/ReportTest.jasper").replace("./", ""));
                       
                       HashMap parameters = new HashMap();
                       
                          JasperPrint jasperPrint = JasperFillManager.fillReport(servletContext.getRealPath("/WEB-INF/reports/ReportTest.jasper").replace("./", ""), parameters, new JREmptyDataSource());
                      
                       ByteArrayOutputStream output = new ByteArrayOutputStream();
                          JasperExportManager.exportReportToPdfStream(jasperPrint, output);
                         
                    HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext().getResponse();
                           response.setContentType("application/pdf");
                    response.addHeader("Content-Disposition","attachment;filename=RankReport.pdf");
                    response.setContentLength(output.size()/*bytes.length*/);
                    ServletOutputStream servletOutputStream = response.getOutputStream();
                    servletOutputStream.write(output.toByteArray(), 0, output.size()/*bytes, 0, bytes.length*/);
                    servletOutputStream.flush();
                    servletOutputStream.close();
                    FacesContext.getCurrentInstance().responseComplete();
               } catch (Exception jre) {
                    jre.printStackTrace();
               }
              }
          }
          


          but the fillReport command returns an exception

          net.sf.jasperreports.engine.JRException: Error loading object from file : /home/cleitonash/java/jboss-4.2.3.GA/server/default/tmp/deploy/tmp1866210135615017893jboss-seam-itext.ear-contents/jboss-seam-itext-exp.war/WEB-INF/reports/ReportTest.jasper



          the structure of my .ear file is

          lib
          META-INF
          jboss-seam.jar
          jboss-seam-itext.jar
          jboss-seam-itext.war
          pdf.keystore



          into the lib package, I put the jasperreports-3.6.0.jar, it already had the commons jars and itext.jar.
          I put ReportTest.jasper into the .war file, in the reports package that is into the WEB-INF.

          anyone know where I'm wrong ? Is something missing ? I don't know where I can't access the file.

          Thanks.


          Click HELP for text formatting instructions. Then edit this text and check the preview.

          • 2. Re: JasperReports with JBoss seam
            cleiton alan  schultz herrmann Newbie

            sorry for the duplication, was not my intention...


            I discovered that when I run the deploy script, my application can't read the .jasper file. It returns the error mentioned above, but if I copy and paste manually the .jasper file into the tmp.... directory into jboss, my application can read the .jasper file, so the .jasper file is being corrupted, maybe for the ant script.


            but when I copy and paste the .jasper file into tmp.... jboss directory, the exception returned in the Jboss Seam Debug Page, is the exception below:




            Exception during request processing:
            Caused by javax.el.ELException with message: "java.lang.reflect.InvocationTargetException
            
            org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:339)
            org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:348)
            org.jboss.el.parser.AstPropertySuffix.invoke(AstPropertySuffix.java:58)
            org.jboss.el.parser.AstValue.invoke(AstValue.java:96)
            org.jboss.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
            org.jboss.seam.core.Expressions$2.invoke(Expressions.java:175)
            org.jboss.seam.navigation.Pages.callAction(Pages.java:692)
            org.jboss.seam.navigation.Pages.preRender(Pages.java:330)
            org.jboss.seam.jsf.SeamPhaseListener.preRenderPage(SeamPhaseListener.java:561)
            org.jboss.seam.jsf.SeamPhaseListener.beforeRenderResponse(SeamPhaseListener.java:472)
            org.jboss.seam.jsf.SeamPhaseListener.beforeServletPhase(SeamPhaseListener.java:148)
            org.jboss.seam.jsf.SeamPhaseListener.beforePhase(SeamPhaseListener.java:118)
            com.sun.faces.lifecycle.Phase.handleBeforePhase(Phase.java:214)
            com.sun.faces.lifecycle.Phase.doPhase(Phase.java:96)
            com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
            javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
            org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
            org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
            org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
            org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
            org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
            org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
            org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
            org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
            org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:368)
            org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:495)
            org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
            org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60)
            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
            org.jboss.seam.web.HotDeployFilter.doFilter(HotDeployFilter.java:53)
            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
            org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
            org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
            org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
            org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
            org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
            org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
            org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
            org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
            org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
            org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
            org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
            org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
            org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
            org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
            org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
            org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
            java.lang.Thread.run(Thread.java:619)
            
            Caused by java.lang.reflect.InvocationTargetException with message: 
            
            sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            java.lang.reflect.Method.invoke(Method.java:597)
            org.jboss.seam.util.Reflections.invoke(Reflections.java:22)
            org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:32)
            org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
            org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:28)
            org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
            org.jboss.seam.core.BijectionInterceptor.aroundInvoke(BijectionInterceptor.java:77)
            org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
            org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:44)
            org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
            org.jboss.seam.core.SynchronizationInterceptor.aroundInvoke(SynchronizationInterceptor.java:32)
            org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
            org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
            org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:185)
            org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:103)
            org.jboss.seam.example.pdf.ReportAction_$$_javassist_seam_2.create(ReportAction_$$_javassist_seam_2.java)
            sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            java.lang.reflect.Method.invoke(Method.java:597)
            org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:335)
            org.jboss.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:348)
            org.jboss.el.parser.AstPropertySuffix.invoke(AstPropertySuffix.java:58)
            org.jboss.el.parser.AstValue.invoke(AstValue.java:96)
            org.jboss.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:276)
            org.jboss.seam.core.Expressions$2.invoke(Expressions.java:175)
            org.jboss.seam.navigation.Pages.callAction(Pages.java:692)
            org.jboss.seam.navigation.Pages.preRender(Pages.java:330)
            org.jboss.seam.jsf.SeamPhaseListener.preRenderPage(SeamPhaseListener.java:561)
            org.jboss.seam.jsf.SeamPhaseListener.beforeRenderResponse(SeamPhaseListener.java:472)
            org.jboss.seam.jsf.SeamPhaseListener.beforeServletPhase(SeamPhaseListener.java:148)
            org.jboss.seam.jsf.SeamPhaseListener.beforePhase(SeamPhaseListener.java:118)
            com.sun.faces.lifecycle.Phase.handleBeforePhase(Phase.java:214)
            com.sun.faces.lifecycle.Phase.doPhase(Phase.java:96)
            com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
            javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
            org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
            org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
            org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
            org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
            org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
            org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
            org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
            org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
            org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:368)
            org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:495)
            org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
            org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60)
            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
            org.jboss.seam.web.HotDeployFilter.doFilter(HotDeployFilter.java:53)
            org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
            org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
            org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
            org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
            org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
            org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
            org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
            org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
            org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:182)
            org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
            org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
            org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
            org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
            org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
            org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
            org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
            org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
            org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
            java.lang.Thread.run(Thread.java:619)