2

I am attempting to generate a cross tab report using JasperReports. The column contains time periods and the row contains different group by conditions. Now I need to change the styling of the row headers based on the level. For example, in the grid shown below, web and email need to be in bold while the other row headers are as is.

enter image description here

Now, I have a field in the bean that lets me decide if I should make the text bold or not, so I tried to use this in a conditional style as below

<style name="rowStyle" hAlign="Center">
   <conditionalStyle>
      <conditionExpression><![CDATA[$V{level}.intValue() != 0]]></conditionExpression>
         <style isBold="true" hAlign="Left"/>
   </conditionalStyle>
   <conditionalStyle>
      <conditionExpression><![CDATA[$V{level}.intValue() == 0]]></conditionExpression>
         <style isBold="false" hAlign="Right"/>
   </conditionalStyle>
</style>

and I have a field and a measure expression corresponding to this

<field name="level" class="java.lang.Integer"/>

<measure name="level" class="java.lang.Integer">
   <measureExpression><![CDATA[$F{level}]]></measureExpression>
</measure>

However this style does nothing when used inside the crosstabRowHeader, it takes effect only inside crosstabCell. So my questions are

  • Is anyway for me to use a conditional style inside the crosstabRowHeader?
  • More specifically, can I access any bean property within the crosstabRowHeader?
Alex K
  • 22,315
  • 19
  • 108
  • 236
Raam
  • 10,296
  • 3
  • 26
  • 27

1 Answers1

0

Managed to figure this out after all. So the issue is to be able to access a property from the bean within the crosstabrowheader (or any other cross tab headers). To do this first create a field corresponding to the bean as so -

<field name="voBean" class="com.jasper.reports.voBean"> <fieldDescription>_THIS</fieldDescription> </field>

Then in the headers, specify this bean as the bucket class.

<rowGroup name="voBean" width="200"> <bucket class="com.jasper.reports.voBean"> <bucketExpression><![CDATA[$F{voBean}]]></bucketExpression> </bucket>

You can now start to access any property on the bean as below

<textFieldExpression><![CDATA[$V{voBean}.getRowName()]]></textFieldExpression>

Hope this helps anybody else with the same problem.

Raam
  • 10,296
  • 3
  • 26
  • 27