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

From java, override expression value of a JRTextField


spambal2
Go to solution Solved by spambal2,

Recommended Posts

Hello,

In my report, I need to put some placeholders for additional calculations that our client could want to see appear in the PDF. The use case is our report by default shows some account balances on a statement, but the client needs to be able to specify some additional balances that should be shown, and those balances should be 100% configuration by the client.

So for example, let's say that in a group footer I have 2 text fields A and B which respectively show the values of 2 balances stored in $V{A} and $V{B}.

I'm also adding a third field C in the footer, but I leave its expression empty so by default if won't show any text. 

The client might want to use this field to show for example the sum of A+B. Or they might want to show A-B or 2*A+2*B, whatever.

Now from my Java program where I'm compiling the report to get a JasperReport object, I'm able to locate the JRTextField element which corresponds to C. I'm able to set a few parameters on this object, but I'm not able to set the Expression because the JRExpression object only has getters and no setters. But I need to be able to override the empty expression to for example "$V{A}+$V{B}".

Again, I need to be able to do this from Java (I'm using the Library) because the client will not have access to Jaspersoft Studio and this override needs to be done dynamically.

How can I do that?

Many thanks,

Didier

Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

  • Solution

Answering my own question. I didn't realize I could load my design into a JasperDesign object. From there I can override anything that I want, including a text field's expression, and then compile this design object into a JasperReport object. My mistake was wanting to modify the report directly instead of the design.

Cheers

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