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

styles conditional inheritance


alexeysem

Recommended Posts

Hi,

I need to implement a different colouring for odd/even rows in a table, and keep these styles information in a separate styles template. Is there a way to do that?

Now I'm trying the following, based on what I've found in "The Definite Guide to Jasper Reports".

Styles template file:

	<style name="Table Details 1" isDefault="false" style="Default" mode="Opaque" backcolor="#E5F5FA">
	<box>
		<pen lineWidth="1.0" lineStyle="Solid" lineColor="#003A63"       />
	</box>
</style>
<style name="Table Details 2" isDefault="false" style="Default" mode="Opaque" backcolor="#FFFFFF">
	<box>
		<pen lineWidth="1.0" lineStyle="Solid" lineColor="#FFFFFF"       />
	</box>
</style>

Jrxml file:

	<style name="Table Details Cond" style="Table Details 1">
	<conditionalStyle>
		<conditionExpression><![CDATA[boolean.valueOf($V{REPORT_COUNT}.intValue() % 2 == 0)]]></conditionExpression>
		<style style="Table Details 2"      />
	</conditionalStyle>
</style>

Surprisingly, this doesn't work, style "Table Details 2" is never used, which means that switching to a different style template conditionally isn't possible. However, I really do need to keep those styles in a separate template.

Is this a bug?.. Any ideas, how to overcome this feature?

Thanks in advance.

Link to comment
Share on other sites

  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Conditional formatting cannot be defined in external style templates.

It would be useful to have it. I have heard the request before, but I'm not sure if it's listed as a tracker item. You could check and log it if it's not already there. It should go on the JasperReports tracker rather than the iReport tracker.

The technical reasons why it isn't supported today are perhaps clear if you think about it. A "normal" conditional style could refer to any field or variable in the report. Once you move the style out of the report into an external style sheet, these may no longer be valid. It's very difficult to handle them well.

Clearly your example of using $V{REPORT_COUNT} could be allowed. We know that variable will be available in any report. But there's not yet a mechanism to sort the good from the bad, so JR cannot handle any conditional formatting in external style templates.

Regards,
Matt

Link to comment
Share on other sites

Matt, thanks for the quick reply, very useful, even though your answer is "no".

I don't know the details of the styles' implementation in JasperReports, however this seems possible. The condition just defines the values for the style's parameters, or the template style from which these values should be taken.

Accordingly the schema, condition only can be defined in the jrxml file, not in the files with style templates, so there's actually no problem with referring to variables/fields.

Also, <style> element nested in <conditionalStyle> has attribute "style" which means that it should accept a reference to a parent style, and it doesn't. Imho this is a 100% bug, isn't it?

So, from my point of view either @style should be removed from <style> nested in <conditionalStyle> or this functionality should be implemented properly. What do you think?

I'm going to post a corresponding bug in the JasperReports bugtrack.

Thanks,
Alexey
 

Link to comment
Share on other sites

  • 6 months later...
  • 1 year later...

 Hi,

I am facing the same problem as the person posted here before. I like the concept of having an external style sheet, what I don't like is having to define the styles for style conditions locally. It's fine to define the conditions locally, but it's unefficient to use locally defined styles for this. Why can we not reference styles from style templates? If I have hundreds of reports to maintain, using external styles for style conditions is clearly an advantage.

Thanks,

Diddy

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