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

Setting non-trivial parameter values


vickirk

Recommended Posts

Hi,

I'm wanting to set a parameter to a value but the expression
to set it is non trival and I really need to execute a few
lines of code to get the value.  The value I'm trying to set
is a date for yesterday to use in a query.  I could change
the sql to do this but I'd prefer to keep that DB neutral.

iReport does not allow me to write a few lines of intermediate
code to get the value so I thought I'd try

new java.util.Date() {{
    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.MILLISECOND, 0);
    cal.set(Calendar.SECOND, 0);
    cal.set(Calendar.MINUTE, 0);
    cal.set(Calendar.HOUR, 0);
    cal.add(Calendar.DAY_OF_YEAR, -1);
    setTime(cal.getTime().getTime());
}}



This compiles but causes an error (a NoClassDefFoundError)
when I try to execute the report with JasperReport running
under the bundled tomcat instance, so it looks like the
anonymous class is not being found by the classloader.

If I put this on say the RequestDate on the sample Frieght
Report I get the error:

java.lang.Exception: 1 - ParamMany_1229428016587_36887 (wrong name: ParamMany_1229428016587_36887$1)
      at com.jaspersoft.jasperserver.irplugin.wsclient.WSClient.runReport(WSClient.java:394)
      at com.jaspersoft.jasperserver.irplugin.wsclient.WSClient.runReport(WSClient.java:311)
      at com.jaspersoft.jasperserver.irplugin.ReportRunner.run(ReportRunner.java:80)
      at java.lang.Thread.run(Unknown Source)  



Is there any other mechanism to set a variable to a non-
trivial value in a jrxml file?

Thanks, Vic
 

Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Anonymous/inner classes in report expressions are not currently supported.

What you can do is to put this code into a static method of a helper class, compile the class, put the compiled class/jar on the application&iReport classpaths, and call this method in your report expression (e.g. <defaultValueExpression>com.me.DateUtils.yesterday()</defaultValueExpression).

Regards,

Lucian

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