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

More than 1 line of code for variable assignment


rapthor

Recommended Posts

Hello,

I wonder how it is possible to work with a Java-Object in iReport that I can use for variable assignments later. For example, I am initializing a GregorianCalendar-Object by using its setTime() method:

GregorianCalendar gc = new GregorianCalendar();
gc.setTime(${DATE});

I want to store this object instance somewhere in my report (like a code snippet that is executed once). I want to use the stored object instance to use the following expression as assignment for a new variable:

gc.getTimeInMillis()

How/where is it possible to store several lines of code that can be re-used in the report using iReport?

Thanks in advance!

Link to comment
Share on other sites

  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

You can create your own class, add it to the iReport classpath (Tools->Options->iReport->Classpath) and reference it in any expression  you want in this way:

com.my.package.MyClass.myStaticMethod( $F{what_I_need} )

If you need to save the instance returned by some initialization method, I suggest you to use a variable of type System.

This type of variables are never modified by JasperReports, so you can init them with a default expression, and their value does not change (if not explicitally changed by the user).

Giulio

Link to comment
Share on other sites

Hi,

i have crerated to two methods in the one java file. one method is used to set the values to object and another method is used to reterive the object.

Object: it is Pojo Class with contains 10 variables

and the reterived obejct is stored in the Varaible  type: System

so in the detail band, i using that Varaible and calling the getter method of the class Type. some time the values are populating in to the reports and sometimes its not populating.

can any one help to solve this issue

 

 

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