[#8461] - Replace template style (jrtx) with report style (jrxml)

Category:
Enhancement request
Priority:
Normal
Status:
Resolved
Project: Severity:
Minor
Resolution:
Fixed
Component: Reproducibility:
N/A
Assigned to:

A style template file (.jrtx) that contains the following definitions:

<style name="DataRow" style="Base"/>
<style name="DataRowNUMERIC" style="DataRow" hTextAlign="Right"/>
<style name="DataRowYMD" style="DataRow" pattern="yyyy-MMM-dd"/>
<style name="DataRowYM" style="DataRow" pattern="yyyy-MMM"/>

A report template file (.jrxml) uses the definitions as follows:

<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement style="DataRowYMD" x="0" y="0" width="80" height="17"/>
<textFieldExpression><![CDATA[$F{ordered}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement style="DataRow" x="80" y="0" width="70" height="17"/>
<textFieldExpression><![CDATA[$F{order}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement style="DataRow" x="150" y="0" width="60" height="17"/>
<textFieldExpression><![CDATA[$F{status}]]></textFieldExpression>
</textField>
<textField isStretchWithOverflow="true" isBlankWhenNull="true">
<reportElement style="DataRowBOOLEAN" x="210" y="0" width="50" height="17"/>
<textFieldExpression><![CDATA[$F{transcript} ? 'Y' : 'N']]></textFieldExpression>
</textField>

Adding a conditional expression requires updating the .jrxml file:

<style name="DataRow" style="Base">
<conditionalStyle>
<conditionExpression><![CDATA[$V{REPORT_COUNT} %2 == 1]]></conditionExpression>
<style mode="Opaque" backcolor="#EEEEEE"/>
</conditionalStyle>
</style>

The definition in the .jrxml file should *replace* the definition in the .jrtx file. This is not the case as the background color for "DataRowBOOLEAN" and "DataRowYMD", which both inherit from "DataRow" never alternates as expected.

The work around is to duplicate definitions for "DataRowYMD", "DataRowYM", "DataRowBOOLEAN", and all the other styles:

<style name="DataRowNUMERIC" style="DataRow" hTextAlign="Right"/>
<style name="DataRowYMD" style="DataRow" pattern="yyyy-MMM-dd"/>
<style name="DataRowYM" style="DataRow" pattern="yyyy-MMM"/>
<style name="DataRowMONEY" style="DataRowNUMERIC" pattern="#,##0.00"/>
<style name="DataRowQUEUED" style="DataRowNUMERIC"/>
<style name="DataRowBOOLEAN" style="DataRow" hTextAlign="Center"/>
etc.

Duplicating definitions just to add conditional styling defeats the purpose of style templates.

An alternative is to allow conditional styles inside the style template. This is possible if the style template is injected into the report during a different phase of the report filling process.

v6.3
thangalin's picture
1323
Joined: Apr 21 2008 - 4:34am
Last seen: 2 years 5 months ago

3 Comments:

#1

To clarify, the full work around becomes:

<style name="DataRow" style="DataRow">
<conditionalStyle>
<conditionExpression><![CDATA[$V{REPORT_COUNT} %2 == 1]]></conditionExpression>
<style mode="Opaque" backcolor="#EEEEEE"/>
</conditionalStyle>
</style>
<style name="DataRowBOOLEAN" style="DataRowBOOLEAN">
<conditionalStyle>
<conditionExpression><![CDATA[$V{REPORT_COUNT} %2 == 1]]></conditionExpression>
<style mode="Opaque" backcolor="#EEEEEE"/>
</conditionalStyle>
</style>
<style name="DataRowNUMERIC" style="DataRowNUMERIC">
<conditionalStyle>
<conditionExpression><![CDATA[$V{REPORT_COUNT} %2 == 1]]></conditionExpression>
<style mode="Opaque" backcolor="#EEEEEE"/>
</conditionalStyle>
</style>
<style name="DataRowYMD" style="DataRowYMD">
<conditionalStyle>
<conditionExpression><![CDATA[$V{REPORT_COUNT} %2 == 1]]></conditionExpression>
<style mode="Opaque" backcolor="#EEEEEE"/>
</conditionalStyle>
</style>
<style name="DataRowYM" style="DataRowYM">
<conditionalStyle>
<conditionExpression><![CDATA[$V{REPORT_COUNT} %2 == 1]]></conditionExpression>
<style mode="Opaque" backcolor="#EEEEEE"/>
</conditionalStyle>
</style>
<style name="DataRowMONEY" style="DataRowMONEY">
<conditionalStyle>
<conditionExpression><![CDATA[$V{REPORT_COUNT} %2 == 1]]></conditionExpression>
<style mode="Opaque" backcolor="#EEEEEE"/>
</conditionalStyle>
</style>
<style name="DataRowQUEUED" style="DataRowQUEUED">
<conditionalStyle>
<conditionExpression><![CDATA[$V{REPORT_COUNT} %2 == 1]]></conditionExpression>
<style mode="Opaque" backcolor="#EEEEEE"/>
</conditionalStyle>
</style>

There should be a way to avoid all this duplication...

#2
  • Status:New» Feedback Requested
  • Assigned:nobody» teodord

Hi,

There is an extension point in JRL for what we call "style providers".
It allows writing custom code to alter the style of the report based on field, variable or custom properties values.

https://github.com/TIBCOSoftware/jasperreports/tree/master/jasperreports...

There is a built-in implementation of a style provider which allows altering the style of an element using custom properties for each style property:
http://jasperreports.sourceforge.net/config.reference.html#net.sf.jasper...

I hope this helps.
Teodor

#3
  • Resolution:Open» Fixed
  • Status:Feedback Requested» Resolved

Hi,

Conditional styles support has been added to the master branch and will be part of the next release.
It relies on a limitation which says that in a JRTX conditionExpression you can only use simple/single $P, $F and $V references, because these external report expression are not actually going to be compiled.
So you can basically only point to boolean parameters, fields or variables in the external conditional styles expressions.

I hope this helps.
Teodor

Feedback
randomness