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

filterexpression depending on parent reports field


theohoekstra

Recommended Posts

Hi,

I have a report with a subreport, and the filterexpression of the subreport is defined in a field of the parent's dataset (as a String). 

My datasources are CSV datasources.

Is there a way to set/compile/evaluate the filterexpression of the subreport at runtime?

Thanks!



Post Edited by theohoekstra at 01/07/2010 12:05
Link to comment
Share on other sites

  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Hi Kacper,

Thanks for your reply.

My 'problem' is that I have my filter expression as a string, for example

"new Boolean($F{field1}.startsWith(\"Am\"))". I can pass this as a parameter to the subreport, and fill the filterExpression with this parameter, but it is a String (and not a Boolean).

The subreport should be filled using different filters for example:

"new Boolean($F{field1}.startsWith(\"Am\"))"

"new Boolean($F{field2}.equals(\"To\"))"

And these filters are defined in a field of the parent report's dataset.

Somehow, I need the filter string to be converted to an expression, and insert it to the JRFillDataset instance handling the datasource.

Best regards,

Theo

Link to comment
Share on other sites

One solution is to dynamically alter the subreport template at fill time by setting the filter expression, and then compiling the subreport in order to use it.

Or theoretically you could use a Java interpreter such as Grovvy or BeanShell to evaluate the expression.  But that wouldn't be straightforward either.

Regards,

Lucian

Link to comment
Share on other sites

Hello Lucian,

Thanks for the suggested solutions. The interpreter or jrxml alteration crossed my mind, but I wanted to be sure there was no easier solution I had overlooked.

I now solved my problem by splitting my csv files by a preprocessor, and dynamically creating a new csv datasource for the specific file I need for the subreport.

Thanks, best regards,

Theo Hoekstra 

 

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