Jasper reports property with condition / dynamic text forecolor

0

<p>I have a simple text field in a subreport.</p>
<p><strong>Goal:</strong> Apply <em>"propertyExpression"</em> for <em>"Forecolor"</em> only when the parameter "evenRow" is <strong><em>1</em></strong></p>
<p>Following does not work but I gave it a try...</p>
<p>&nbsp;</p>
<pre language="xml">&lt;textField&gt;
  &lt;reportElement key="" mode="Transparent" x="108" y="1" width="76" height="13"&gt;
    &lt;propertyExpression name="net.sf.jasperreports.style.forecolor"&gt;
        &lt;![CDATA[$P{evenRow}.equals("1") ? $P{colorZebra1_text} : ""]]&gt;
    &lt;/propertyExpression&gt;
  &lt;/reportElement&gt;
  &lt;textElement&gt;&lt;font fontName="SansSerif" size="8"/&gt;&lt;/textElement&gt;
  &lt;textFieldExpression&gt;"Text"&lt;/textFieldExpression&gt;
&lt;/textField&gt;
</pre>
<p>&nbsp;</p>
<p><strong style="margin: 0px; padding: 0px; border: 0px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-numeric: inherit; font-weight: bold; font-stretch: inherit; font-size: 15px; line-height: inherit; font-family: Arial, &quot;Helvetica Neue&quot;, Helvetica, sans-serif; vertical-align: baseline; color: rgb(36, 39, 41); letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial;">Context</strong><span style="color: rgb(36, 39, 41); font-family: Arial, &quot;Helvetica Neue&quot;, Helvetica, sans-serif; font-size: 15px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;">: The parent report calls this! subreport which contains the textfield multiple times (illustrated in attached image). Each time it is called the parent report sends the parameter<span class="Apple-converted-space">&nbsp;</span></span><em style="margin: 0px; padding: 0px; border: 0px; font-style: italic; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-numeric: inherit; font-weight: normal; font-stretch: inherit; font-size: 15px; line-height: inherit; font-family: Arial, &quot;Helvetica Neue&quot;, Helvetica, sans-serif; vertical-align: baseline; color: rgb(36, 39, 41); letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial;">"evenRow"</em><span style="color: rgb(36, 39, 41); font-family: Arial, &quot;Helvetica Neue&quot;, Helvetica, sans-serif; font-size: 15px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;"><span class="Apple-converted-space">&nbsp;</span>as either 1 or 0...</span></p>
<p>&nbsp;</p>
<pre language="xml">//snipped from parent report to show that "evenROW" is 1 or 0
($V{REPORT_COUNT}.intValue() % 2 == 0 ?   1 :    0)</pre>
<br />
<p><strong>Question:</strong> How can I create a propertyExpression for the dynamic "Forecolor" that only comes to effect when my parameter <em>"evenRow"</em> is set to <strong><em>1</em></strong> ?</p>
<p>&nbsp;<a href="https://i.stack.imgur.com/yzfee.png" rel="nofollow noreferrer"><img alt="enter image description here" src="https://i.stack.imgur.com/yzfee.png" /></a></p>
<p><em>Note:</em> I am aware I could use <a href="http://community.jaspersoft.com/blog/change-font-color-based-condition-j..." rel="nofollow noreferrer">conditional styles</a> -&gt; The problem with styles in general is that they are never dynamic, i.e. I would have to create 1 style for every single color that 'could' be set ...and because the color can be set to whatever hex value this is not an option.</p>
 

dunham's picture
35
Joined: Oct 18 2013 - 6:57am
Last seen: 1 month 1 week ago

0 Answers:

No answers yet
Feedback