title: How to exclude a textfield from printing when its value is equal to zero in JasperReports
body: <p>I have a database where there are fields with values as zero.</p>
  
  <p><a href="https://i.stack.imgur.com/a4zX6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/a4zX6.png" alt="enter image description here"></a></p>
  
  <p>I have jsp page where I will write the sql query and send the sql query as parameter to the JasperReports </p>
  
  <p>invoicePDF.jsp</p>
  
  <pre><code>&lt;%
  Integer id = (Integer) session.getAttribute("id");
  System.out.println("id is:"+id);
  String sql=null;
  Connection conn = null;
  String termsOfPmnt = (String)session.getAttribute("termsOfPmnt");
  String dispThrough = (String)session.getAttribute("dispThrough");
  try 
  {
      Class.forName("com.mysql.jdbc.Driver");
      conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/marketing_database","root","root");
      sql="select company_profile.companyName, and_so_on  from company_profile,invoice,invoiceclient_details where invoice.CId='"+id+"' and invoiceclient_details.CId='"+id+"'";  
      ServletContext context = request.getServletContext(); 
      String fullPath = context.getRealPath("/WEB-INF/reports/report5.jrxml");
      InputStream input = new FileInputStream(new File(fullPath));
      JasperDesign jasperDesign = JRXmlLoader.load(input);
  
      JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
  
      HashMap&lt;String,Object&gt; map = new HashMap&lt;String,Object&gt;();
      map.put("sql",sql);
              byte[] bytes = JasperRunManager.runReportToPdf(jasperReport, map, conn);
  
              response.setContentType("application/pdf");
              response.setContentLength(bytes.length);
              ServletOutputStream outputStream = response.getOutputStream();
              outputStream.write(bytes, 0, bytes.length);
              outputStream.flush();
              outputStream.close();
              conn.close();
  }
  catch(Exception e) 
  {e.printStackTrace();} 
  
          %&gt;
  </code></pre>
  
  <p>and the jasper report code is as follows</p>
  
  <pre><code>        &lt;detail&gt;
      &lt;band height="140" splitType="Prevent"&gt;
          &lt;textField isStretchWithOverflow="true"&gt;
              &lt;reportElement positionType="Float" stretchType="RelativeToTallestObject" x="0" y="0" width="13" height="20" isPrintWhenDetailOverflows="true" uuid="24b49d3f-5c78-4a19-a4d2-e2cbff95a40d"/&gt;
              &lt;box&gt;
                  &lt;topPen lineWidth="0.5"/&gt;
                  &lt;leftPen lineWidth="0.5"/&gt;
                  &lt;bottomPen lineWidth="0.5"/&gt;
                  &lt;rightPen lineWidth="0.5"/&gt;
              &lt;/box&gt;
              &lt;textElement textAlignment="Center" verticalAlignment="Middle"&gt;
                  &lt;font fontName="Times New Roman" pdfFontName="Times-Roman" isPdfEmbedded="true"/&gt;
              &lt;/textElement&gt;
              &lt;textFieldExpression&gt;&lt;![CDATA[$V{serial number}]]&gt;&lt;/textFieldExpression&gt;
          &lt;/textField&gt;
          &lt;textField isStretchWithOverflow="true"&gt;
              &lt;reportElement positionType="Float" stretchType="RelativeToTallestObject" x="13" y="0" width="242" height="20" isPrintWhenDetailOverflows="true" uuid="4332ae75-6371-4879-b805-9d07254f0784"/&gt;
              &lt;box&gt;
                  &lt;topPen lineWidth="0.5"/&gt;
                  &lt;leftPen lineWidth="0.5"/&gt;
                  &lt;bottomPen lineWidth="0.5"/&gt;
                  &lt;rightPen lineWidth="0.5"/&gt;
              &lt;/box&gt;
              &lt;textElement textAlignment="Center" verticalAlignment="Middle"&gt;
                  &lt;font fontName="Times New Roman" pdfFontName="Times-Roman" isPdfEmbedded="true"/&gt;
              &lt;/textElement&gt;
              &lt;textFieldExpression&gt;&lt;![CDATA[$F{DescriptionOfGoods}]]&gt;&lt;/textFieldExpression&gt;
          &lt;/textField&gt;
          &lt;textField isStretchWithOverflow="true"&gt;
              &lt;reportElement positionType="Float" stretchType="RelativeToTallestObject" x="309" y="0" width="86" height="20" isPrintWhenDetailOverflows="true" uuid="54828e8d-bae0-4669-873e-36de8bf54446"/&gt;
              &lt;box&gt;
                  &lt;topPen lineWidth="0.5"/&gt;
                  &lt;leftPen lineWidth="0.5"/&gt;
                  &lt;bottomPen lineWidth="0.5"/&gt;
                  &lt;rightPen lineWidth="0.5"/&gt;
              &lt;/box&gt;
              &lt;textElement textAlignment="Center" verticalAlignment="Middle"&gt;
                  &lt;font fontName="Times New Roman" pdfFontName="Times-Roman" isPdfEmbedded="true"/&gt;
              &lt;/textElement&gt;
              &lt;textFieldExpression&gt;&lt;![CDATA[$F{PerUnitPrice}]]&gt;&lt;/textFieldExpression&gt;
          &lt;/textField&gt;
          &lt;staticText&gt;
              &lt;reportElement positionType="Float" stretchType="RelativeToTallestObject" x="395" y="0" width="64" height="20" isPrintWhenDetailOverflows="true" uuid="e02408a1-2bcd-4fb9-94d3-ed0c0c1d8ff6"/&gt;
              &lt;box&gt;
                  &lt;topPen lineWidth="0.5"/&gt;
                  &lt;leftPen lineWidth="0.5"/&gt;
                  &lt;bottomPen lineWidth="0.5"/&gt;
                  &lt;rightPen lineWidth="0.5"/&gt;
              &lt;/box&gt;
              &lt;textElement textAlignment="Center" verticalAlignment="Middle" markup="none"&gt;
                  &lt;font fontName="Times New Roman" pdfFontName="Times-Roman" isPdfEmbedded="true"/&gt;
              &lt;/textElement&gt;
              &lt;text&gt;&lt;![CDATA[Nos]]&gt;&lt;/text&gt;
          &lt;/staticText&gt;
          &lt;textField isStretchWithOverflow="true" pattern="###0.00"&gt;
              &lt;reportElement positionType="Float" stretchType="RelativeToTallestObject" x="459" y="0" width="96" height="20" isPrintWhenDetailOverflows="true" uuid="00ba44d4-b287-4a29-8bf3-1ad07da760e8"/&gt;
              &lt;box&gt;
                  &lt;topPen lineWidth="0.5"/&gt;
                  &lt;leftPen lineWidth="0.5"/&gt;
                  &lt;bottomPen lineWidth="0.5"/&gt;
                  &lt;rightPen lineWidth="0.5"/&gt;
              &lt;/box&gt;
              &lt;textElement textAlignment="Center" verticalAlignment="Middle"&gt;
                  &lt;font fontName="Times New Roman" pdfFontName="Times-Roman" isPdfEmbedded="true"/&gt;
              &lt;/textElement&gt;
              &lt;textFieldExpression&gt;&lt;![CDATA[$F{Quantity} *$F{PerUnitPrice}]]&gt;&lt;/textFieldExpression&gt;
          &lt;/textField&gt;
          &lt;textField isStretchWithOverflow="true"&gt;
              &lt;reportElement positionType="Float" stretchType="RelativeToTallestObject" x="255" y="0" width="54" height="20" isPrintWhenDetailOverflows="true" uuid="d74b9bd4-9608-44a7-b46e-55f39ed0c852"/&gt;
              &lt;box&gt;
                  &lt;topPen lineWidth="0.5"/&gt;
                  &lt;leftPen lineWidth="0.5"/&gt;
                  &lt;bottomPen lineWidth="0.5"/&gt;
                  &lt;rightPen lineWidth="0.5"/&gt;
              &lt;/box&gt;
              &lt;textElement textAlignment="Center" verticalAlignment="Middle"&gt;
                  &lt;font fontName="Times New Roman" pdfFontName="Times-Roman" isPdfEmbedded="true"/&gt;
              &lt;/textElement&gt;
              &lt;textFieldExpression&gt;&lt;![CDATA[$F{Quantity}]]&gt;&lt;/textFieldExpression&gt;
          &lt;/textField&gt;
          &lt;staticText&gt;
              &lt;reportElement x="0" y="20" width="309" height="20" uuid="6e493a3e-c559-493b-ac86-314eb0df5a16"/&gt;
              &lt;box&gt;
                  &lt;topPen lineWidth="0.5"/&gt;
                  &lt;leftPen lineWidth="0.5"/&gt;
                  &lt;bottomPen lineWidth="0.5"/&gt;
              &lt;/box&gt;
              &lt;text&gt;&lt;![CDATA[]]&gt;&lt;/text&gt;
          &lt;/staticText&gt;
          &lt;staticText&gt;
              &lt;reportElement positionType="Float" stretchType="RelativeToTallestObject" x="309" y="20" width="86" height="20" isPrintWhenDetailOverflows="true" uuid="89f04225-eaba-4adc-a675-495d45ad27b2"/&gt;
              &lt;box&gt;
                  &lt;topPen lineWidth="0.5"/&gt;
                  &lt;leftPen lineWidth="0.0"/&gt;
                  &lt;bottomPen lineWidth="0.5"/&gt;
                  &lt;rightPen lineWidth="0.0"/&gt;
              &lt;/box&gt;
              &lt;textElement textAlignment="Left" verticalAlignment="Middle"&gt;
                  &lt;font fontName="Times New Roman" pdfFontName="Times-Roman" isPdfEmbedded="true"/&gt;
              &lt;/textElement&gt;
              &lt;text&gt;&lt;![CDATA[SubTotal:]]&gt;&lt;/text&gt;
          &lt;/staticText&gt;
          &lt;textField isStretchWithOverflow="true"&gt;
              &lt;reportElement positionType="Float" stretchType="RelativeToTallestObject" x="395" y="20" width="160" height="20" uuid="0e1bf36a-76f9-4644-a218-6c3bdcf2d1d1"/&gt;
              &lt;box&gt;
                  &lt;topPen lineWidth="0.5"/&gt;
                  &lt;leftPen lineWidth="0.0"/&gt;
                  &lt;bottomPen lineWidth="0.5"/&gt;
                  &lt;rightPen lineWidth="0.5"/&gt;
              &lt;/box&gt;
              &lt;textElement textAlignment="Left" verticalAlignment="Middle"&gt;
                  &lt;font fontName="Times New Roman"/&gt;
              &lt;/textElement&gt;
              &lt;textFieldExpression&gt;&lt;![CDATA[$V{subtotal}]]&gt;&lt;/textFieldExpression&gt;
          &lt;/textField&gt;
          &lt;staticText&gt;
              &lt;reportElement x="0" y="40" width="309" height="20" uuid="0a7f98e0-4db9-4ddc-a385-0e511193cb89"/&gt;
              &lt;box&gt;
                  &lt;topPen lineWidth="0.5"/&gt;
                  &lt;leftPen lineWidth="0.5"/&gt;
                  &lt;bottomPen lineWidth="0.5"/&gt;
              &lt;/box&gt;
              &lt;text&gt;&lt;![CDATA[]]&gt;&lt;/text&gt;
          &lt;/staticText&gt;
          &lt;staticText&gt;
              &lt;reportElement positionType="Float" stretchType="RelativeToTallestObject" x="309" y="40" width="86" height="20" isPrintWhenDetailOverflows="true" uuid="2f4cf4d5-51cd-435e-9279-c36e1bb578f0"/&gt;
              &lt;box&gt;
                  &lt;topPen lineWidth="0.5"/&gt;
                  &lt;leftPen lineWidth="0.0"/&gt;
                  &lt;bottomPen lineWidth="0.5"/&gt;
                  &lt;rightPen lineWidth="0.0"/&gt;
              &lt;/box&gt;
              &lt;textElement textAlignment="Left" verticalAlignment="Middle"&gt;
                  &lt;font fontName="Times New Roman" pdfFontName="Times-Roman" isPdfEmbedded="true"/&gt;
              &lt;/textElement&gt;
              &lt;text&gt;&lt;![CDATA[VAT5.5:]]&gt;&lt;/text&gt;
          &lt;/staticText&gt;
          &lt;textField isStretchWithOverflow="true"&gt;
              &lt;reportElement positionType="Float" stretchType="RelativeToTallestObject" x="395" y="40" width="160" height="20" uuid="137c41e0-787d-4778-a9bf-1dd13d64fa3c"/&gt;
              &lt;box&gt;
                  &lt;topPen lineWidth="0.5"/&gt;
                  &lt;leftPen lineWidth="0.0"/&gt;
                  &lt;bottomPen lineWidth="0.5"/&gt;
                  &lt;rightPen lineWidth="0.5"/&gt;
              &lt;/box&gt;
              &lt;textElement textAlignment="Left" verticalAlignment="Middle"&gt;
                  &lt;font fontName="Times New Roman" pdfFontName="Times-Roman" isPdfEmbedded="true"/&gt;
              &lt;/textElement&gt;
              &lt;textFieldExpression&gt;&lt;![CDATA[$F{vat5Amount}]]&gt;&lt;/textFieldExpression&gt;
          &lt;/textField&gt;
          &lt;staticText&gt;
              &lt;reportElement x="0" y="60" width="309" height="20" uuid="70bd70aa-541d-424e-8dff-4febd8afbe32"/&gt;
              &lt;box&gt;
                  &lt;topPen lineWidth="0.5"/&gt;
                  &lt;leftPen lineWidth="0.5"/&gt;
                  &lt;bottomPen lineWidth="0.5"/&gt;
              &lt;/box&gt;
              &lt;text&gt;&lt;![CDATA[]]&gt;&lt;/text&gt;
          &lt;/staticText&gt;
          &lt;staticText&gt;
              &lt;reportElement positionType="Float" stretchType="RelativeToTallestObject" x="309" y="60" width="86" height="20" isPrintWhenDetailOverflows="true" uuid="929d9003-99cc-4f5d-b80f-8df5cb11af70"/&gt;
              &lt;box&gt;
                  &lt;topPen lineWidth="0.5"/&gt;
                  &lt;leftPen lineWidth="0.0"/&gt;
                  &lt;bottomPen lineWidth="0.5"/&gt;
                  &lt;rightPen lineWidth="0.0"/&gt;
              &lt;/box&gt;
              &lt;textElement textAlignment="Left" verticalAlignment="Middle"&gt;
                  &lt;font fontName="Times New Roman" pdfFontName="Times-Roman" isPdfEmbedded="true"/&gt;
              &lt;/textElement&gt;
              &lt;text&gt;&lt;![CDATA[VAT14.5]]&gt;&lt;/text&gt;
          &lt;/staticText&gt;
          &lt;textField isStretchWithOverflow="true"&gt;
              &lt;reportElement positionType="Float" stretchType="RelativeToTallestObject" x="395" y="60" width="160" height="20" uuid="7e8c8d41-2847-4a84-b068-22f40cd2e472"/&gt;
              &lt;box&gt;
                  &lt;topPen lineWidth="0.5"/&gt;
                  &lt;leftPen lineWidth="0.0"/&gt;
                  &lt;bottomPen lineWidth="0.5"/&gt;
                  &lt;rightPen lineWidth="0.5"/&gt;
              &lt;/box&gt;
              &lt;textElement textAlignment="Left" verticalAlignment="Middle"&gt;
                  &lt;font fontName="Times New Roman" pdfFontName="Times-Roman" isPdfEmbedded="true"/&gt;
              &lt;/textElement&gt;
              &lt;textFieldExpression&gt;&lt;![CDATA[$F{vat14Amount}]]&gt;&lt;/textFieldExpression&gt;
          &lt;/textField&gt;
          &lt;staticText&gt;
              &lt;reportElement x="0" y="80" width="309" height="20" uuid="42d1448c-3e4e-4144-96c3-9d964c7296a9"/&gt;
              &lt;box&gt;
                  &lt;topPen lineWidth="0.5"/&gt;
                  &lt;leftPen lineWidth="0.5"/&gt;
                  &lt;bottomPen lineWidth="0.5"/&gt;
              &lt;/box&gt;
              &lt;text&gt;&lt;![CDATA[]]&gt;&lt;/text&gt;
          &lt;/staticText&gt;
          &lt;staticText&gt;
              &lt;reportElement positionType="Float" stretchType="RelativeToTallestObject" x="309" y="80" width="86" height="20" isPrintWhenDetailOverflows="true" uuid="ae220695-756d-48e3-b194-4e08baf43a46"/&gt;
              &lt;box&gt;
                  &lt;topPen lineWidth="0.5"/&gt;
                  &lt;leftPen lineWidth="0.0"/&gt;
                  &lt;bottomPen lineWidth="0.5"/&gt;
                  &lt;rightPen lineWidth="0.0"/&gt;
              &lt;/box&gt;
              &lt;textElement textAlignment="Left" verticalAlignment="Middle"&gt;
                  &lt;font fontName="Times New Roman" pdfFontName="Times-Roman" isPdfEmbedded="true"/&gt;
              &lt;/textElement&gt;
              &lt;text&gt;&lt;![CDATA[Service Tax:]]&gt;&lt;/text&gt;
          &lt;/staticText&gt;
          &lt;textField isStretchWithOverflow="true"&gt;
              &lt;reportElement positionType="Float" stretchType="RelativeToTallestObject" x="395" y="80" width="160" height="20" uuid="930d451c-232a-4bc9-9527-f8e207b023fc"/&gt;
              &lt;box&gt;
                  &lt;topPen lineWidth="0.5"/&gt;
                  &lt;leftPen lineWidth="0.0"/&gt;
                  &lt;bottomPen lineWidth="0.5"/&gt;
                  &lt;rightPen lineWidth="0.5"/&gt;
              &lt;/box&gt;
              &lt;textElement textAlignment="Left" verticalAlignment="Middle"&gt;
                  &lt;font fontName="Times New Roman" pdfFontName="Times-Roman" isPdfEmbedded="true"/&gt;
              &lt;/textElement&gt;
              &lt;textFieldExpression&gt;&lt;![CDATA[$F{svcTaxAmount}]]&gt;&lt;/textFieldExpression&gt;
          &lt;/textField&gt;
          &lt;staticText&gt;
              &lt;reportElement x="0" y="100" width="309" height="20" uuid="63075a73-38d7-4954-951f-9f2169622ff8"/&gt;
              &lt;box&gt;
                  &lt;topPen lineWidth="0.5"/&gt;
                  &lt;leftPen lineWidth="0.5"/&gt;
                  &lt;bottomPen lineWidth="0.5"/&gt;
              &lt;/box&gt;
              &lt;text&gt;&lt;![CDATA[]]&gt;&lt;/text&gt;
          &lt;/staticText&gt;
          &lt;staticText&gt;
              &lt;reportElement positionType="Float" stretchType="RelativeToTallestObject" x="309" y="100" width="86" height="20" isPrintWhenDetailOverflows="true" uuid="002ff00b-29e6-44f1-bc9c-0b1e6d8c1504"/&gt;
              &lt;box&gt;
                  &lt;topPen lineWidth="0.5"/&gt;
                  &lt;leftPen lineWidth="0.0"/&gt;
                  &lt;bottomPen lineWidth="0.5"/&gt;
                  &lt;rightPen lineWidth="0.0"/&gt;
              &lt;/box&gt;
              &lt;textElement textAlignment="Left" verticalAlignment="Middle"&gt;
                  &lt;font fontName="Times New Roman" pdfFontName="Times-Roman" isPdfEmbedded="true"/&gt;
              &lt;/textElement&gt;
              &lt;text&gt;&lt;![CDATA[CST:]]&gt;&lt;/text&gt;
          &lt;/staticText&gt;
          &lt;staticText&gt;
              &lt;reportElement x="0" y="120" width="309" height="20" uuid="e440c11d-5996-48a4-95bf-d1eae7ba0291"/&gt;
              &lt;box&gt;
                  &lt;topPen lineWidth="0.5"/&gt;
                  &lt;leftPen lineWidth="0.5"/&gt;
                  &lt;bottomPen lineWidth="0.5"/&gt;
              &lt;/box&gt;
              &lt;text&gt;&lt;![CDATA[]]&gt;&lt;/text&gt;
          &lt;/staticText&gt;
          &lt;staticText&gt;
              &lt;reportElement positionType="Float" stretchType="RelativeToTallestObject" x="309" y="120" width="86" height="20" isPrintWhenDetailOverflows="true" uuid="d7e3353f-4990-4299-a24f-9826f6265f84"/&gt;
              &lt;box&gt;
                  &lt;topPen lineWidth="0.5"/&gt;
                  &lt;leftPen lineWidth="0.0"/&gt;
                  &lt;bottomPen lineWidth="0.5"/&gt;
                  &lt;rightPen lineWidth="0.0"/&gt;
              &lt;/box&gt;
              &lt;textElement textAlignment="Left" verticalAlignment="Middle"&gt;
                  &lt;font fontName="Times New Roman" pdfFontName="Times-Roman" isPdfEmbedded="true"/&gt;
              &lt;/textElement&gt;
              &lt;text&gt;&lt;![CDATA[Grand Total]]&gt;&lt;/text&gt;
          &lt;/staticText&gt;
          &lt;textField isStretchWithOverflow="true" pattern=""&gt;
              &lt;reportElement positionType="Float" stretchType="RelativeToTallestObject" isPrintRepeatedValues="false" x="395" y="120" width="160" height="20" isPrintWhenDetailOverflows="true" uuid="9a1ac07c-8237-468f-bd1a-a6f5c4e6a1ee"/&gt;
              &lt;box&gt;
                  &lt;topPen lineWidth="0.5"/&gt;
                  &lt;leftPen lineWidth="0.0"/&gt;
                  &lt;bottomPen lineWidth="0.5"/&gt;
                  &lt;rightPen lineWidth="0.5"/&gt;
              &lt;/box&gt;
              &lt;textElement textAlignment="Left" verticalAlignment="Middle"&gt;
                  &lt;font fontName="Times New Roman" pdfFontName="Times-Roman" isPdfEmbedded="true"/&gt;
              &lt;/textElement&gt;
              &lt;textFieldExpression&gt;&lt;![CDATA[$F{GrandTotal}]]&gt;&lt;/textFieldExpression&gt;
          &lt;/textField&gt;
          &lt;frame&gt;
              &lt;reportElement x="395" y="100" width="160" height="20" uuid="ae76daa8-a3de-4ba2-a258-7d67c5deb710"&gt;
                  &lt;printWhenExpression&gt;&lt;![CDATA[$F{cstAmount}!=null &amp;&amp; $F{cstAmount}.doubleValue()&gt;0]]&gt;&lt;/printWhenExpression&gt;
              &lt;/reportElement&gt;
              &lt;box&gt;
                  &lt;topPen lineWidth="0.5"/&gt;
                  &lt;leftPen lineWidth="0.5"/&gt;
                  &lt;bottomPen lineWidth="0.5"/&gt;
                  &lt;rightPen lineWidth="0.5"/&gt;
              &lt;/box&gt;
          &lt;/frame&gt;
      &lt;/band&gt;
  &lt;/detail&gt;
  </code></pre>
  
  <p>Now my question is when JasperReports's report is printing the values it should exclude the row in which the field is zero.</p>
  
  <p>For Example:</p>
  
  <p>I have vat5,vat14,servicetax and cst.If vat5 is zero and vat14,servicetax and cst are not zero then it should print vat14,servicetax and cst.Likewise if vat14 is zero and vat5,servicetax,cst are not zero then it should print vat5,servicetax,cst so that it exclude printing vat14 as zero in report</p>