Jump to content
We've recently updated our Privacy Statement, available here ×

How to use one field to add a backcolor of another using conditionalStyle


jzonisin
Go to solution Solved by rpachipu,

Recommended Posts

I have a list of statement entries where I display most fields but I also have 2 fields which I want to use as flags in the report.
They have no use beyond the conditional styling. The fields are isFirstDayOfMonth and isLastDayOfMonth which are Booleans.

I have checked around and I don't find a standalone boolean being but it shouldn't be problem, I imagine.

I am using styling as follows:

<style name="first">
<conditionalStyle>
<conditionExpression><![CDATA[$F{isFirstDayOfMonth}]]></conditionExpression>
<style backcolor="#FFFF00"/>
</conditionalStyle>
</style>

and

<detail>
<band height="15">
<property name="com.jaspersoft.studio.unit.height" value="px"/>
<textField>
<reportElement key="date" style="first" x="0" y="0" width="110" height="15" uuid="daa9472f-49fe-4a5f-863b-f2d07be3da9e">
<property name="com.jaspersoft.studio.unit.height" value="px"/>
</reportElement>
<box leftPadding="5">
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
</box>
<textElement>
<font size="10"/>
</textElement>
<textFieldExpression><![CDATA[$F{date}]]></textFieldExpression>
</textField>

but it is not working.

I have declared the fields as follows:

<field name="date" class="java.lang.String"/>
<field name="description" class="java.lang.String"/>
<field name="charge" class="java.lang.Double"/>
<field name="payment" class="java.lang.Double"/>
<field name="balance" class="java.lang.Double"/>
<field name="isFirstDayOfMonth" class="java.lang.Boolean"/>
<field name="isLastDayOfMonth" class="java.lang.Boolean"/>
Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

  • Solution

Hi Jacob, if you want to use one field to add a backcolor of another , you can easily do this by adding property to your textfield than by conditional style.

1. Making the texfiled opaque.

2. appling net.sf.jasperreports.style.backcolor to the textfield.

For eg: Where as c2 field will have  hex color code.

<textField>

<reportElement mode="Opaque" x="127" y="1" width="73" height="30" uuid="41cbd2d7-7379-400f-95a7-bee3824834db">

<propertyExpression name="net.sf.jasperreports.style.backcolor"><![CDATA[$F{col2}]]></propertyExpression>

</reportElement>

<textElement textAlignment="Center" verticalAlignment="Middle"/>

<textFieldExpression><![CDATA[$F{col2}]]></textFieldExpression>

</textField>

 

Link to comment
Share on other sites

  • 1 month later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...