3 Replies Latest reply on Feb 4, 2009 5:48 PM by andres hurtado

    Seam 2.0.2.SP1 - Jasper Report Integration problem

    Darryl Sibeon Newbie

      Hey everyone,


      I am working on a rather large project using jboss seam and recently we have upgraded to Seam 2.0.2.SP1.  Everything went smoothly except for the report generation.  The class DocType is no longer included in the project, it has been changed for DocumentType. 


      We changed our DocType.PDF to new DocumentType(pdf, application/pdf).  The reports are being generated correctly, but in Firefox 3.0 they are opened in the save dialogue instead of the imbedded reader (we have checked the configurations in the browser) also in Internet Explorer the file doesn't open nor save. 


      Below is the example of the report generator we use, the only mod we made in the new code was adding the new DocumentType as cited above. 


      All our report classes extend this class, an example of thiss is also posted below. 


      Any ideas as to why these reports aren´t opening in the browser would be greatly appreciated.




      Thanks in advance!!


      Darryl A. Sibeon



      Report Class:RelSeam.java
      package com.snet.relatorios;
      
      import java.io.ByteArrayOutputStream;
      import java.sql.Connection;
      import java.util.HashMap;
      import java.util.Map;
      
      import javax.faces.context.FacesContext;
      import javax.persistence.EntityManager;
      import javax.servlet.ServletContext;
      
      import net.sf.jasperreports.engine.JasperExportManager;
      import net.sf.jasperreports.engine.JasperFillManager;
      import net.sf.jasperreports.engine.JasperPrint;
      
      import org.jboss.seam.annotations.In;
      import org.jboss.seam.faces.FacesMessages;
      import org.jboss.seam.pdf.DocumentData;
      import org.jboss.seam.pdf.DocumentStore;
      import org.jboss.seam.pdf.DocumentData.DocType;
      import org.jboss.seam.persistence.HibernateSessionProxy;
      
      import com.snet.entidades.Usuario;
       
      public abstract class RelSeam {
              @In
              private Usuario usuarioLogado;
              @In
              private HibernateSessionProxy session;
              @In
              private FacesMessages facesMessages;
              @In
              private EntityManager entityManager;
              @In(value="org.jboss.seam.pdf.documentStore", create=true)
              private DocumentStore documentStore;
              
              private ServletContext servletContext = (ServletContext)FacesContext.getCurrentInstance().getExternalContext().getContext();
              private String serverRootpath =  servletContext.getRealPath("/");
      
              protected abstract String getReportPath();  
      
              protected abstract Map<String, Object> getParams();
      
              @SuppressWarnings("deprecation")  
              public String print() {  
      
                      String reportUrl = getReportPath();    
      
                      try {  
                              Map<String, Object> params = new HashMap<String, Object>();  
      
                              params.putAll(getParams());
                              
                              Connection connection =  session.connection();
      
                              JasperPrint jasperPrint = JasperFillManager.fillReport(this.getServerRootpath() + this.getReportPath(), params, connection);  
                              connection.close();
                              ByteArrayOutputStream output = new ByteArrayOutputStream();  
                              JasperExportManager.exportReportToPdfStream(jasperPrint, output);  
      
                              String reportId = documentStore.newId();
                              DocumentData data = new DocumentData("Report #" + reportId , DocType.PDF, output.toByteArray());  
                              documentStore.saveData(reportId, data);  
                              
                              return "/seam-doc?docId=" + reportId;
      
                      } catch (Exception e) { 
                              e.printStackTrace();
                              facesMessages.instance().add("Erro ao criar relatorio :"+e.getMessage());
                              return null;  
                      } 
              }
            /*Getters and Setters omitted*/
      }
      
      
      Extension of report class: ReportExample.java
      
      package com.snet.relatorios;
      
      import java.io.Serializable;
      
      import java.util.HashMap;
      import java.util.Map;
      
      import org.jboss.seam.ScopeType;
      import org.jboss.seam.annotations.Name;
      import org.jboss.seam.annotations.Scope;
      import org.jboss.seam.faces.FacesMessages;
      
      @Name("reportExample")
      @Scope(ScopeType.PAGE)
      public class ReportExample extends RelSeam implements Serializable{
              private static final long serialVersionUID = -6837381799414220874L;
      
              
              @Override
              protected String getReportPath() {
                      return "/reports/example.jasper";
              }
              
              @Override
              protected Map<String, Object> getParams() {
                      Map<String, Object> mapa = new HashMap<String, Object>();
                      mapa.put("SUBREPORT_DIR", this.getServerRootpath()+"/reports/");
                      return mapa;
              }
      
              @Override
              public String print() {
                      return this.dadosValidos()?super.print():null;
              }
      }