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

Pattern property and parameters


europe72

Recommended Posts

 Hello,

 

I am wondering whether or not the pattern property of a field is capable of evaluating a parameter, or if it will only accept a string literal representing a format.

Meaning, if I wanted to pass in a formatting string via a parameter (e.g. paramMyFormat = "#,###.00"), and if I specified for a certain field's pattern, that parameter (e.g. $P{paramMyFormat}) will Jasper evaluate the parameter or not?

 

My trials are suggesting not, and I am wondering if I need to write a scriptlet to evaluate the parameter and then format the field?

 

Thanks in advance

Link to comment
Share on other sites

  • 2 weeks later...
  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

No, the pattern cannot be directly specified by a parameter.

You can define conditional styles if you have a predefined set of possible patterns.  If you need to support any pattern, you can manually instantiate a java.text.DecimalFormat and use it in the text field expression to format the value.  The drawnback of this approach is that you wouldn't be able to export the value as numerical cell in Excel.

Regards,

Lucian

Link to comment
Share on other sites

  • 7 months later...

I tried setting up conditional styles to set a different pattern (number of decimal places on a numeric field) based on a parameter. But the pattern doesn't seem to be applied at all. I know the conditions in the conditional styles are correct because to debug them I also assigned each a diferent forecolor, and that is applied correctly to the field, but the pattern isn't. Any ideas as to why? Thanks.

 

EDIT: Fixed! There seems to be a bug in iReport: my field originally had a fixed pattern, which I removed when I created the conditional style so that it wouldn't override the style. The problem, as I found by looking at the jrxml source, is that iReport didn't actually erase the pattern attribute, instead setting it as pattern="". After erasing it directly in the jrxml source, the style started working correctly. It seems that once you assign a pattern through the iReport GUI, it can't be fully removed without editing the source by hand.

To sum up: erasing a previously set pattern from a field in iReport results in:

<textField pattern="" ... >

In order for a conditional pattern style applied to that field to work, the empty pattern has to be removed by hand:

<textField ... >




Post Edited by powermacx at 02/07/2011 21:28
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...