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

dynamic pageheader text


nedPhillips

Recommended Posts

I need to dynamically display static header text if any of the values in a field contains a certain value.

 

Trying to use the 'Print When' feature is useless in this case because iReport considers every value of every row. I only want to display the header text if any of the rows has a certain value in a certain field.

 

for example if I have a field called 'Color' and if any of the rows contains a value of 'blue' I want to display the header text 'THERE IS BLUE COLOR INCLUDED WITH THE RESULTS' otherwise if no rows has a color blue then don't display the header text above.

Post edited by: nedPhillips, at: 2008/06/09 17:34

Link to comment
Share on other sites

  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

Ned,

 

It sounds like the key idea that you need to use is variables. I would attack the problem like this:

 

1. Create variable "BlueCount" as a java.lang.Integer. Calculation type is "Sum". Initial value is new Integer(0). Variable expression is something like this:

$F{myField}.equalsIgnoreCase( "blue" )

? new Integer(1)

: new Integer(0)

 

2. Create a text field in the page header with logic like this:

($V{BlueCount}.intValue() > 0)

? "Special Header"

: "Boring Header"

 

There are lots of possible variations, of course. I used an integer to sum up the blues, but you could use a boolean instead, etc.

 

Most likely gotcha: be sure to set an appropriate Evaluation Time for the text field. If it's set to "Now" then BlueCount may be 0 because it hasn't read through the rows yet. Set it to "Report" (or another appropriate value).

 

Regards,

Matt

JasperSoft

Link to comment
Share on other sites

Thanks mdahlman, I got got my report to work better by using your design, however, it only works for the current page. For example, in reference to my previous example, if I have a 'blue' value in a row on any page but the first page then the pageheader text will not display.

 

I tried setting the 'reset type' and 'increment type' for the variable, but it still only reflectes the first page.

 

My problem could very well be because I do not quite understand how you explain how to 'Create a text field' in your 2nd step.

 

In other words, I'm not sure where the 'logic' you provided should go. Maybe in the 'Print When Expression' of the static text field?

 

Thanks again for responding.

Post edited by: nedPhillips, at: 2008/06/10 16:57

Link to comment
Share on other sites

Can someone help with this.

 

I've tried the approach suggested by mdahlman, but it only seems to look at the first record returned.

 

For example using my example above, if the first row returned has a color value of 'blue' in the 'Color' column then the header text displays. If the color value of 'blue' is in the last row then the header text does not display.

 

I need the header text to display if ANY of the values of the 'Color' column of ANY row contains a value of 'blue', not just the first row.

Post edited by: nedPhillips, at: 2008/06/11 18:19

Link to comment
Share on other sites

Ned,

 

It sounds like you created a "Static Text" field. What you want is a "Text Field". The buttons are next to each other on the iReport toolbar.

 

When you open the properties for a text field you'll see a tab labeled "Text Field" with a "Text Field Expression".

 

That might clear up the other problem you mention too, because you can appropriately set the "Evaluation Time" on the same tab.

 

Good luck,

Matt

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