Jump to content

Conditional Styles in a CrossTab


mdares

Recommended Posts

Hello,

 

I am trying to conditionally color a column depending on whether the date represented is a weekend or not. I have created the following style at the top of my jrxml:

 

Code:

<style name="Weekend" isDefault="false" mode="Opaque" backcolor="#80FF80">
<conditionalStyle>
<conditionExpression><![CDATA[new Boolean(....utils.DateUtil.isWeekend($F{entryDate}))]]></conditionExpression>
<style isDefault="false" style="Weekend" backcolor="#80FFFF"/>
</conditionalStyle>
</style>

 

I have a dataset used by this crosstab defined as such:

 

 

Code:
[code]
<subDataset name="Vacation">
<field name="costingCode" class="java.lang.Object">
<fieldDescription><![CDATA[costingCode]]></fieldDescription>
</field>
<field name="entryDate" class="java.util.Date">
<fieldDescription><![CDATA[entryDate]]></fieldDescription>
</field>
<field name="hours" class="java.lang.Float">
<fieldDescription><![CDATA[hours]]></fieldDescription>
</field>
<field name="task" class="java.lang.Object">
<fieldDescription><![CDATA[task]]></fieldDescription>
</field>
<filterExpression><![CDATA[new Boolean(((....pojos.CostingCode)$F{costingCode}).getCostingCodeType()==1)]]></filterExpression>
</subDataset>

 

The other places I use the entryDate field within the crosstab work fine but when I try and apply this style I get the error:

 

Code:
[code]
net.sf.jasperreports.engine.design.JRValidationException: Report design not valid :
1. Field not found : entryDate

 

This led me to believe the scope of the field defination may need to be greater than the subdataset and I tried defining the entryDate field directly under the <jasperReport>, but to no avail.

 

Any help would be appreciated - I think that this must be a simple mistake on my part. The report works fine until I apply this style.

 

Matthew Dares

Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Using dataset fields in crosstab conditional styles does not work because it doesn't make sense.

 

Imagine the following scenario: you have a entryDate field in the dataset and you group dataset records in the crosstab per entryDate year. Now if you would use a conditional style that depends on entryDate for the crosstab group header, to what value would entryDate evaluate in the condition expression? A crosstab group/bucket corresponds to many dataset entryDate values. Therefore you can only use the bucket value (via the crosstab variable created for the group) in conditional style expressions.

 

Another scenario: you have a hours field in the dataset and you create a crosstab measure that sums this field per year/task/etc. You cannot use a conditional style that depends on the hours field for a crosstab data cell since, again, a data cell accumulates data for many dataset records. You can only use the accumulated measure value (again via the crosstab variable created for the measure).

 

HTH,

Lucian

Link to comment
Share on other sites

  • 1 year later...

I understand the reason why a bucket header can only be the value of the bucket expression.  However, there is a valid case where I wanted to display something other than the bucket expression value.  For example, one of my buckets is the sum of items for the week, and the bucket expression is formatted as "yyyy-ww".  Now, I wanted to print the date at the start of the week (e.g., "10-19-2008"), instead of the value "2008-42".   Or if I wanted to display a more descriptive text instead of "2008-42" as in the week number of the year. 

The way it is, the group header cannot be anything other than the bucket expression value.

Link to comment
Share on other sites

OK, I finally figured it out that I can use a custom Java class to get to the Sunday (start of the week) of the date in question, and print out the date of that Sunday, instead of printing out the week number of the year.  If anyone has questions on how to do this, contact me.

Link to comment
Share on other sites

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...