dunham Posted July 3, 2017 Share Posted July 3, 2017 <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> </p><pre language="xml"><textField> <reportElement key="" mode="Transparent" x="108" y="1" width="76" height="13"> <propertyExpression name="net.sf.jasperreports.style.forecolor"> <![CDATA[$P{evenRow}.equals("1") ? $P{colorZebra1_text} : ""]]> </propertyExpression> </reportElement> <textElement><font fontName="SansSerif" size="8"/></textElement> <textFieldExpression>"Text"</textFieldExpression></textField></pre><p> </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, "Helvetica Neue", 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, "Helvetica Neue", 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"> </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, "Helvetica Neue", 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, "Helvetica Neue", 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"> </span>as either 1 or 0...</span></p><p> </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> <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-jasper-ireport-work-out-styles" rel="nofollow noreferrer">conditional styles</a> -> 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> Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now