Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to use dynamic variable in "print when expression"?
    text
    copied!<p>I am using <em>iReport</em> for making PDF Report.<br/> My objectives are I want to use dynamic variable (name of variable is <strong><em>pgnum</em></strong>) in my 3 objects elements, and use <strong><em>pgnum</em></strong> in "print when expression" object properties.<br/> I have three objects elements, they are a text field, frame name’s frameA and frame name’s frameB.</p> <p>I want to make something like this in the print when expression :</p> <ul> <li>text field = print when expression : <strong>$V{pgnum} % 6 == 1</strong> </li> <li>frameA = print when expression : <strong>$V{pgnum} % 6 == 1</strong> </li> <li>frameB = print when expression : <strong>$V{pgnum} % 6 != 1</strong></li> </ul> <p>If I have total 14 pages in my PDF so the result I want are :</p> <ul> <li>When the page 7 and page 13, text field and frameA will be print.</li> <li>And the other page(except page 7 and page 13) only frameB will be print.</li> </ul> <p>I was tried all the way in <em>iReport</em> but the <strong><em>pgnum</em></strong> always be static result, even in text field the evaluating time properties is for every page. And frame A never be print too, because I think the <strong><em>pgnum</em></strong> is always set to be zero (0) value, and never be increment. So the result is frame B always be printed in all page. </p> <p>Can you help me to solve this problem using <em>iReport</em>? Or can you suggest or even help me using the other jasper report something like dynamic report or dynamic jasper to solve this problem ?</p> <p>NB:</p> <ul> <li>Name of the dynamic variable is pgnum.</li> <li>My pgnum has initial value 0 (zero)</li> <li>And has properties like this => class="java.lang.Integer" incrementType="Page" calculation="Sum"</li> </ul> <p>Thanks for reading. I’m waiting for your reply soon.</p> <p>Here is my <em>jrxml</em> file:</p> <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;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="deploy_details" language="groovy" pageWidth="502" pageHeight="842" columnWidth="502" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0"&gt; &lt;style name="table_CH" mode="Opaque" backcolor="#999999"&gt; &lt;box&gt; &lt;pen lineWidth="0.5" lineColor="#000000"/&gt; &lt;/box&gt; &lt;/style&gt; &lt;variable name="pgnum" class="java.lang.Integer" incrementType="Page" calculation="Count"&gt; &lt;variableExpression&gt;&lt;![CDATA[pgnum+1]]&gt;&lt;/variableExpression&gt; &lt;initialValueExpression&gt;&lt;![CDATA[0]]&gt;&lt;/initialValueExpression&gt; &lt;/variable&gt; &lt;detail&gt; &lt;band height="762" splitType="Stretch"&gt; &lt;frame&gt; &lt;reportElement isPrintRepeatedValues="false" mode="Opaque" x="56" y="66" width="114" height="43" isRemoveLineWhenBlank="true" isPrintWhenDetailOverflows="true" backcolor="#000000"&gt; &lt;printWhenExpression&gt;&lt;![CDATA[$V{pgnum} % 6 == 1]]&gt;&lt;/printWhenExpression&gt; &lt;/reportElement&gt; &lt;staticText&gt; &lt;reportElement mode="Transparent" x="15" y="12" width="83" height="18" forecolor="#FFFFFF"/&gt; &lt;textElement/&gt; &lt;text&gt;&lt;![CDATA[FrameA]]&gt;&lt;/text&gt; &lt;/staticText&gt; &lt;/frame&gt; &lt;frame&gt; &lt;reportElement isPrintRepeatedValues="false" mode="Opaque" x="185" y="66" width="114" height="43" isRemoveLineWhenBlank="true" isPrintWhenDetailOverflows="true" backcolor="#000000"&gt; &lt;printWhenExpression&gt;&lt;![CDATA[$V{pgnum} % 6 != 1]]&gt;&lt;/printWhenExpression&gt; &lt;/reportElement&gt; &lt;staticText&gt; &lt;reportElement mode="Transparent" x="15" y="12" width="83" height="18" forecolor="#FFFFFF"/&gt; &lt;textElement/&gt; &lt;text&gt;&lt;![CDATA[FrameB]]&gt;&lt;/text&gt; &lt;/staticText&gt; &lt;/frame&gt; &lt;textField isStretchWithOverflow="true" evaluationTime="Page" isBlankWhenNull="true"&gt; &lt;reportElement isPrintRepeatedValues="false" x="122" y="35" width="100" height="20" isRemoveLineWhenBlank="true" isPrintWhenDetailOverflows="true"&gt; &lt;printWhenExpression&gt;&lt;![CDATA[$V{pgnum} % 6 == 1]]&gt;&lt;/printWhenExpression&gt; &lt;/reportElement&gt; &lt;box&gt; &lt;topPen lineWidth="3.25"/&gt; &lt;leftPen lineWidth="3.25"/&gt; &lt;bottomPen lineWidth="3.25"/&gt; &lt;rightPen lineWidth="3.25"/&gt; &lt;/box&gt; &lt;textElement/&gt; &lt;textFieldExpression&gt;&lt;![CDATA["textField"]]&gt;&lt;/textFieldExpression&gt; &lt;/textField&gt; &lt;/band&gt; &lt;/detail&gt; &lt;/jasperReport&gt; </code></pre> <p>Thanks Alex K for reply, but your answer still not solve my problem, I have tried and follow all of your order to solve this problem, but I still get the pgnum in static value (not increment). </p> <p>You suggested me before about dataSource, and now I have included the problem with new jrxml and dataSource example files in testing package. But I have a new problem, the result (dummyData) which I created is always print "empty" in test.pdf, can you help me again, sir? And can you solve my primary objective before, please?</p> <p>Thank you I am waiting for your reply</p> <p>Here's the link: <a href="http://www.mediafire.com/?0c043bhrgzqswff" rel="nofollow">dataSource, jrxml</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload