8 Replies Latest reply: Jan 25, 2012 2:50 PM by Jason Porter RSS

    Seam reports and jasperreports problem...

    hantsy bai Master

      Is there anyone used the Seam 3 reports module and jasperreports?


      I have tried to used them in my project?


      But every strange result in the pdf file in the browser.


      
      <?xml version="1.0" encoding="UTF-8"?>
      <jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="XlsDataSourceReport" pageWidth="595" pageHeight="842" columnWidth="515" leftMargin="40" rightMargin="40" topMargin="50" bottomMargin="50">
           <property name="ireport.zoom" value="1.0"/>
           <property name="ireport.x" value="0"/>
           <property name="ireport.y" value="9"/>
           <style name="Sans_Normal" isDefault="true" fontName="Serif" fontSize="12" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false"/>
           <style name="Sans_Bold" fontName="Serif" fontSize="12" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false"/>
           <style name="Sans_Italic" fontName="Serif" fontSize="12" isBold="false" isItalic="true" isUnderline="false" isStrikeThrough="false"/>
           <parameter name="forwardingCase" class="com.telopsys.siorc.forwarding.model.ForwardingCase"/>
           <field name="id" class="java.lang.Long">
                <fieldDescription><![CDATA[id]]></fieldDescription>
           </field>
           <field name="name" class="java.lang.String">
                <fieldDescription><![CDATA[name]]></fieldDescription>
           </field>
           <field name="description" class="java.lang.String">
                <fieldDescription><![CDATA[description]]></fieldDescription>
           </field>
           <field name="quantity" class="java.lang.Integer">
                <fieldDescription><![CDATA[quantity]]></fieldDescription>
           </field>
           <field name="waybill" class="java.lang.String">
                <fieldDescription><![CDATA[waybill]]></fieldDescription>
           </field>
           <field name="unit" class="com.telopsys.siorc.model.Unit">
                <fieldDescription><![CDATA[unit]]></fieldDescription>
           </field>
           <field name="customsPrice" class="java.lang.Double">
                <fieldDescription><![CDATA[customsPrice]]></fieldDescription>
           </field>
           <field name="currency" class="com.telopsys.siorc.model.Currency">
                <fieldDescription><![CDATA[currency]]></fieldDescription>
           </field>
           <sortField name="name" order="Descending"/>
           <title>
                <band height="140">
                     <line>
                          <reportElement x="0" y="0" width="515" height="1"/>
                     </line>
                     <textField isBlankWhenNull="true">
                          <reportElement style="Sans_Normal" x="0" y="10" width="515" height="30"/>
                          <textElement textAlignment="Center">
                               <font size="22"/>
                          </textElement>
                          <textFieldExpression><![CDATA[$P{forwardingCase}.getForwardingCaseSubject()]]></textFieldExpression>
                          <anchorNameExpression><![CDATA["Title"]]></anchorNameExpression>
                     </textField>
                     <textField isBlankWhenNull="true">
                          <reportElement style="Sans_Bold" x="0" y="40" width="80" height="20"/>
                          <textElement textAlignment="Right"/>
                          <textFieldExpression><![CDATA["Vessel"]]></textFieldExpression>
                     </textField>
                     <textField isBlankWhenNull="true">
                          <reportElement style="Sans_Normal" x="85" y="40" width="160" height="20"/>
                          <textElement textAlignment="Left"/>
                          <textFieldExpression><![CDATA[$P{forwardingCase}.getVessel().getName()]]></textFieldExpression>
                     </textField>
                     <textField isBlankWhenNull="true">
                          <reportElement style="Sans_Bold" x="260" y="40" width="80" height="20"/>
                          <textElement textAlignment="Right"/>
                          <textFieldExpression><![CDATA["Port"]]></textFieldExpression>
                     </textField>
                     <textField isBlankWhenNull="true">
                          <reportElement style="Sans_Normal" x="345" y="40" width="160" height="20"/>
                          <textElement textAlignment="Left"/>
                          <textFieldExpression><![CDATA[$P{forwardingCase}.getPort().getName()]]></textFieldExpression>
                     </textField>
                     <textField isBlankWhenNull="true">
                          <reportElement style="Sans_Bold" x="0" y="60" width="80" height="20"/>
                          <textElement textAlignment="Right"/>
                          <textFieldExpression><![CDATA["Forwarder"]]></textFieldExpression>
                     </textField>
                     <textField isBlankWhenNull="true">
                          <reportElement style="Sans_Normal" x="85" y="60" width="160" height="20"/>
                          <textElement textAlignment="Left"/>
                          <textFieldExpression><![CDATA[$P{forwardingCase}.getForwarder().getFullname()]]></textFieldExpression>
                     </textField>
                     <textField isBlankWhenNull="true">
                          <reportElement style="Sans_Bold" x="260" y="60" width="80" height="20"/>
                          <textElement textAlignment="Right"/>
                          <textFieldExpression><![CDATA["Agent"]]></textFieldExpression>
                     </textField>
                     <textField isBlankWhenNull="true">
                          <reportElement style="Sans_Normal" x="345" y="60" width="160" height="20"/>
                          <textElement textAlignment="Left"/>
                          <textFieldExpression><![CDATA[$P{forwardingCase}.getAgent().getFullname()]]></textFieldExpression>
                     </textField>
                     <textField isBlankWhenNull="true">
                          <reportElement style="Sans_Bold" x="0" y="80" width="80" height="20"/>
                          <textElement textAlignment="Right"/>
                          <textFieldExpression><![CDATA["WayBill"]]></textFieldExpression>
                     </textField>
                     <textField isBlankWhenNull="true">
                          <reportElement style="Sans_Normal" x="85" y="80" width="160" height="20"/>
                          <textElement textAlignment="Left"/>
                          <textFieldExpression><![CDATA[$P{forwardingCase}.getWaybill()]]></textFieldExpression>
                     </textField>
                     <textField isBlankWhenNull="true">
                          <reportElement style="Sans_Bold" x="260" y="80" width="80" height="20"/>
                          <textElement textAlignment="Right"/>
                          <textFieldExpression><![CDATA["Quote"]]></textFieldExpression>
                     </textField>
                     <textField isBlankWhenNull="true">
                          <reportElement style="Sans_Normal" x="345" y="80" width="160" height="20"/>
                          <textElement textAlignment="Left"/>
                          <textFieldExpression><![CDATA[String.valueOf($P{forwardingCase}.getQuote())]]></textFieldExpression>
                     </textField>
                     <textField isBlankWhenNull="true">
                          <reportElement style="Sans_Bold" x="0" y="100" width="80" height="20"/>
                          <textElement textAlignment="Right"/>
                          <textFieldExpression><![CDATA["Invoice"]]></textFieldExpression>
                     </textField>
                     <textField isBlankWhenNull="true">
                          <reportElement style="Sans_Normal" x="85" y="100" width="160" height="20"/>
                          <textElement textAlignment="Left"/>
                          <textFieldExpression><![CDATA[String.valueOf($P{forwardingCase}.getInvoice())]]></textFieldExpression>
                     </textField>
                </band>
           </title>
           <pageHeader>
                <band height="20">
                     <staticText>
                          <reportElement style="Sans_Bold" mode="Opaque"  x="0" y="5" width="60" height="15" forecolor="#FFFFFF" backcolor="#000000"/>
                          <textElement textAlignment="Center"/>
                          <text><![CDATA[Name]]></text>
                     </staticText>
                     <staticText>
                          <reportElement style="Sans_Bold" mode="Opaque" x="60" y="5" width="140" height="15" forecolor="#FFFFFF" backcolor="#000000"/>
                          <textElement textAlignment="Center"/>
                          <text><![CDATA[Description]]></text>
                     </staticText>
                     <staticText>
                          <reportElement style="Sans_Bold" mode="Opaque" x="200" y="5" width="60" height="15" forecolor="#FFFFFF" backcolor="#000000"/>
                          <textElement textAlignment="Center"/>
                          <text><![CDATA[Quantity]]></text>
                     </staticText>
                     <staticText>
                          <reportElement style="Sans_Bold" mode="Opaque" x="260" y="5" width="60" height="15" forecolor="#FFFFFF" backcolor="#000000"/>
                          <textElement textAlignment="Center"/>
                          <text><![CDATA[WayBill]]></text>
                     </staticText>
                     <staticText>
                          <reportElement style="Sans_Bold" mode="Opaque" x="320" y="5" width="60" height="15" forecolor="#FFFFFF" backcolor="#000000"/>
                          <textElement/>
                          <text><![CDATA[Unit]]></text>
                     </staticText>
                     <staticText>
                          <reportElement style="Sans_Bold" mode="Opaque" x="380" y="5" width="60" height="15" forecolor="#FFFFFF" backcolor="#000000"/>
                          <textElement textAlignment="Center"/>
                          <text><![CDATA[Price]]></text>
                     </staticText>
                     <staticText>
                          <reportElement style="Sans_Bold" mode="Opaque" x="440" y="5" width="75" height="15" forecolor="#FFFFFF" backcolor="#000000"/>
                          <textElement textAlignment="Center"/>
                          <text><![CDATA[Currency]]></text>
                     </staticText>
                </band>
           </pageHeader>
           <detail>
                <band height="15">
                     <textField isStretchWithOverflow="true">
                          <reportElement positionType="Float" x="0" y="0" width="60" height="15"/>
                          <box leftPadding="5" rightPadding="5">
                               <leftPen lineWidth="0.5"/>
                               <bottomPen lineWidth="0.5"/>
                          </box>
                          <textElement textAlignment="Left"/>
                          <textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
                     </textField>
                     <textField isStretchWithOverflow="true">
                          <reportElement positionType="Float" x="60" y="0" width="140" height="15"/>
                          <box leftPadding="5" rightPadding="5">
                               <leftPen lineWidth="0.5"/>
                               <bottomPen lineWidth="0.5"/>
                          </box>
                          <textElement textAlignment="Left"/>
                          <textFieldExpression><![CDATA[$F{description}]]></textFieldExpression>
                     </textField>
                     <textField isStretchWithOverflow="true">
                          <reportElement positionType="Float" x="200" y="0" width="60" height="15"/>
                          <box leftPadding="5" rightPadding="5">
                               <leftPen lineWidth="0.5"/>
                               <bottomPen lineWidth="0.5"/>
                          </box>
                          <textElement/>
                          <textFieldExpression><![CDATA[""+ String.valueOf($F{quantity})]]></textFieldExpression>
                     </textField>
                     <textField isStretchWithOverflow="true">
                          <reportElement positionType="Float" x="260" y="0" width="60" height="15"/>
                          <box leftPadding="5" rightPadding="5">
                               <leftPen lineWidth="0.5"/>
                               <bottomPen lineWidth="0.5"/>
                          </box>
                          <textElement/>
                          <textFieldExpression><![CDATA[$F{waybill}]]></textFieldExpression>
                     </textField>
                     <textField isStretchWithOverflow="true">
                          <reportElement positionType="Float" x="320" y="0" width="60" height="15"/>
                          <box leftPadding="5" rightPadding="5">
                               <leftPen lineWidth="0.5"/>
                               <bottomPen lineWidth="0.5"/>
                          </box>
                          <textElement/>
                          <textFieldExpression><![CDATA[$F{unit}.getName()]]></textFieldExpression>
                     </textField>
                     <textField isStretchWithOverflow="true">
                          <reportElement positionType="Float" x="380" y="0" width="60" height="15"/>
                          <box leftPadding="5" rightPadding="5">
                               <leftPen lineWidth="0.5"/>
                               <bottomPen lineWidth="0.5"/>
                          </box>
                          <textElement/>
                          <textFieldExpression><![CDATA[String.valueOf($F{customsPrice})]]></textFieldExpression>
                     </textField>
                     <textField isStretchWithOverflow="true">
                          <reportElement positionType="Float" x="440" y="0" width="75" height="15"/>
                          <box leftPadding="5" rightPadding="5">
                               <leftPen lineWidth="0.5"/>
                               <bottomPen lineWidth="0.5"/>
                               <rightPen lineWidth="0.5"/>
                          </box>
                          <textElement/>
                          <textFieldExpression><![CDATA[""+ $F{currency}.getName()+"("+$F{currency}.getCode()+")"]]></textFieldExpression>
                     </textField>
                </band>
           </detail>
           <pageFooter>
                <band height="40">
                     <line>
                          <reportElement x="0" y="10" width="515" height="1"/>
                     </line>
                     <textField>
                          <reportElement x="200" y="20" width="80" height="15"/>
                          <textElement textAlignment="Right"/>
                          <textFieldExpression><![CDATA["Page " + String.valueOf($V{PAGE_NUMBER}) + " of"]]></textFieldExpression>
                     </textField>
                     <textField evaluationTime="Report">
                          <reportElement x="280" y="20" width="75" height="15"/>
                          <textElement/>
                          <textFieldExpression><![CDATA[" " + String.valueOf($V{PAGE_NUMBER})]]></textFieldExpression>
                     </textField>
                </band>
           </pageFooter>
           <lastPageFooter>
                <band height="60">
                     <textField>
                          <reportElement x="0" y="10" width="515" height="15"/>
                          <textElement textAlignment="Center"/>
                          <textFieldExpression><![CDATA["There were " +
                               String.valueOf($V{REPORT_COUNT}) +
                               " address records on this report."]]></textFieldExpression>
                          <anchorNameExpression><![CDATA["Summary"]]></anchorNameExpression>
                     </textField>
                     <line>
                          <reportElement x="0" y="30" width="515" height="1"/>
                     </line>
                     <textField>
                          <reportElement x="200" y="40" width="80" height="15"/>
                          <textElement textAlignment="Right"/>
                          <textFieldExpression><![CDATA["Page " + String.valueOf($V{PAGE_NUMBER}) + " of"]]></textFieldExpression>
                     </textField>
                     <textField evaluationTime="Report">
                          <reportElement x="280" y="40" width="75" height="15"/>
                          <textElement/>
                          <textFieldExpression><![CDATA[" " + String.valueOf($V{PAGE_NUMBER})]]></textFieldExpression>
                     </textField>
                </band>
           </lastPageFooter>
      </jasperReport>
      
      




      The text in the page Hear and footer are not displayed.


        • 1. Re: Seam reports and jasperreports problem...
          George Gastaldi Master

          Can you paste a sample code ? Are you using ReportCompiler to create a ReportDefinition ? Which version are you using ?


          Regards,


          George Gastaldi
          Seam Reports Leader

          • 2. Re: Seam reports and jasperreports problem...
            hantsy bai Master

            I have posted the original codes here.


            http://seamframework.org/Community/ContextNotActiveException


            OK, I  pasted the latest modified version.


            @WebServlet(urlPatterns = { "/forwarding/caseExportPdfServlet" })
            public class ExportPdfServlet extends HttpServlet {
                 private static final long serialVersionUID = 1L;
                 private static final Logger log = LoggerFactory
                           .getLogger(ExportPdfServlet.class);
            
                 @Inject
                 @RequestParam
                 Long id;
            
                 @Inject
                 @RequestParam
                 String cid;
            
                 @Inject
                 @Utility
                 EntityManager em;
            
                 @Inject
                 private ResourceProvider resourceProvider;
            
                 @Inject
                 @Jasper
                 ReportCompiler compiler;
            
                 @Inject
                 @PDF
                 @Jasper
                 ReportRenderer<Report> pdfRenderer;
            
                 /**
                  * @see HttpServlet#HttpServlet()
                  */
                 public ExportPdfServlet() {
                      super();
                      // TODO Auto-generated constructor stub
                 }
            
                 @Override
                 public void destroy() {
                      // TODO Auto-generated method stub
                      super.destroy();
            
                 }
            
                 @Override
                 public void init() throws ServletException {
                      // TODO Auto-generated method stub
                      super.init();
                      // conversation.begin(cid);
                 }
            
                 /**
                  * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
                  *      response)
                  */
                 protected void doGet(HttpServletRequest request,
                           HttpServletResponse response) throws ServletException, IOException {
                      processRequest(request, response);
                 }
            
                 /**
                  * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
                  *      response)
                  */
                 protected void doPost(HttpServletRequest request,
                           HttpServletResponse response) throws ServletException, IOException {
                      processRequest(request, response);
                 }
            
                 protected void processRequest(HttpServletRequest request,
                           HttpServletResponse response) throws ServletException, IOException {
                      if (log.isDebugEnabled()) {
                           log.debug("call processRequest");
                           log.debug("request param id@" + id);
                      }
                      List<ForwardingCase> _cases = em
                                .createQuery(
                                          "select distinct c from ForwardingCase c left join c.forwardingItems items where c.id=:id", ForwardingCase.class)
                                .setParameter("id", id).getResultList();
            
                      ForwardingCase _case = null;
                      if (!_cases.isEmpty()) {
                           _case=_cases.get(0);
                      }
                      
                      if(_case==null){
                           throw new EntityNotFoundException();
                      }
            
                      OutputStream _out = response.getOutputStream();
            
                      InputStream sourceReport = resourceProvider
                                .loadResourceStream("/reports/forwarding-case.jrxml");
                      JRDataSource jasperDataSource = new JRBeanCollectionDataSource(
                                _case.getForwardingItems());
            
                      // source
                      ReportDefinition report = compiler.compile(sourceReport);
            
                      Map<String, Object> params = new HashMap<String, Object>();
                      params.put("forwardingCase", _case);
            
                      Report reportInstance = report.fill(jasperDataSource, params);
            
                      // ByteArrayOutputStream os = new ByteArrayOutputStream(_out); //
                      // OutputStream
                      // Render output as the desired content
                      pdfRenderer.render(reportInstance, _out);
                      _out.flush();
                 }
            
            

             

            • 3. Re: Seam reports and jasperreports problem...
              George Gastaldi Master

              hantsy,


              I opened your report on iReports 4.1.1 and the Header and the footer is not shown on the preview tab, which clearly indicates a bug on your report OR JasperReports (hardly). Seam Reports is just using JasperReports API so it´s not a bug from Seam Reports.

              • 4. Re: Seam reports and jasperreports problem...
                hantsy bai Master

                Another version in jsf back bean...the same result.


                // export pdf
                     @Inject
                     FacesContext context;
                
                     @Inject
                     @Jasper
                     private transient ReportCompiler compiler;
                
                     @Inject
                     @PDF
                     @Jasper
                     private transient ReportRenderer pdfRenderer;
                
                     public void export() throws IOException {
                          if (log.isDebugEnabled()) {
                               log.debug("call export...");
                          }
                          ExternalContext externalContext = context.getExternalContext();
                          externalContext.setResponseContentType("application/pdf");
                
                          OutputStream _out = externalContext.getResponseOutputStream();
                
                          InputStream sourceReport = resourceProvider
                                    .loadResourceStream("/reports/forwarding-case.jrxml");
                          JRDataSource jasperDataSource = new JRBeanCollectionDataSource(
                                    this.currentForwardingCase.getForwardingItems());
                
                          // source
                          ReportDefinition report = compiler.compile(sourceReport);
                
                          Map<String, Object> params = new HashMap<String, Object>();
                          params.put("forwardingCase", this.currentForwardingCase);
                
                          Report reportInstance = report.fill(jasperDataSource, params);
                
                          // ByteArrayOutputStream os = new ByteArrayOutputStream(_out); //
                          // OutputStream
                          // Render output as the desired content
                          pdfRenderer.render(reportInstance, _out);
                          //_out.flush();
                          externalContext.responseFlushBuffer();
                
                          context.responseComplete();
                
                     }
                
                

                • 5. Re: Seam reports and jasperreports problem...
                  Jason Porter Master

                  I don't think you saw what George said just before your last post Hantsy. There's a problem with your report, not Seam report or the other code you're creating.

                  • 6. Re: Seam reports and jasperreports problem...
                    hantsy bai Master

                    The pageFooter and lastPageFooter is from the seam reports test suite, without any modification.


                    OK, let me research the jasperrepots document firstly...

                    • 7. Re: Seam reports and jasperreports problem...
                      Waldemar Quincke Newbie

                      Can someone show a complete sample with seam reports, please ?


                      Thanks.

                      • 8. Re: Seam reports and jasperreports problem...
                        Jason Porter Master

                        When you mean complete what exactly are you talking about? The unit tests (don't recall off hand if there's an example) show a complete in that it works and shows you how to use it example.