JasperReport's compileReport throws NullPointerException

Hi,

I am new to Jasper reports plugin in Servoy. I am using the following software versions for development:

  1. Servoy IDE Version: 5.2.0 - build 997
  2. plugins\servoy_jasperreports\jasperreports-3.7.1
  3. iReport 3.7.1
  4. jConnect-5_5
  5. Sybase IAnywhere 11

When I to try run plugins.jasperPluginRMI.compileReport(“C:\report5.jrxml”, “C:\report5.jasper”), the following exception is displayed:

java.lang.NullPointerException
at com.servoy.plugins.jasperreports.JasperReportRunner.adjustFileUnix(JasperReportRunner.java:321)
at com.servoy.plugins.jasperreports.JasperReportsServer.jasperCompile(JasperReportsServer.java:256)
at com.servoy.plugins.jasperreports.JasperReportsProvider.js_compileReport(JasperReportsProvider.java:547)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:179)
at org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:353)

The report5.jrxml can be compiled without errors and can be displayed in preview screen in IReport 3.7.1. I just dropped the JasperReport plugin in plugins folder of the development server. I saw the JasperReport plugin icon in the menu of Servoy IDE and used it like the syntax above. Did I miss out some installation instructions?

Thanks.

Why don’t you use the jasper file directly then if it’s compiled in iReport?
I don’t know if this will solve further problems but using the jrxml in Servoy just adds the overhead of compilation to your solution, so you could avoid it using the jasper file directly in your runReport() method.

my 2 cents :)

ptalbot:
Why don’t you use the jasper file directly then if it’s compiled in iReport?
I don’t know if this will solve further problems but using the jrxml in Servoy just adds the overhead of compilation to your solution, so you could avoid it using the jasper file directly in your runReport() method.

my 2 cents :)

Thanks for the reply.

The reason for this is I need to recreate the jrxml file at runtime. This will allow me to include user-based parameters in the report such as changing titlename, field names, etc.

Did I forget to set an attribute before running compileReport method? Because it seems that it is looking for an attribute that’s why it’s causing a NullPointerException.

You can set properties for that! Pass them as arguments to the runReport() method and use $P{nameOfProperty} instead of messing up with the jrxml structure.
This is a lot safer and quicker too!

Looking at the sources, I see no other arguments for the compileReport method, but since the Exception happens in the adjustFileUnix() method, I think you should try using:

plugins.jasperPluginRMI.compileReport("C:/report5.jrxml", "C:/report5.jasper");

[EDIT]
Actually looking closer, it seems your report directory is null, so go to the admin, plugins page, and set the path of the “directory.jasper.report” property to the place where you will hold your reports.

ptalbot:
[EDIT]
Actually looking closer, it seems your report directory is null, so go to the admin, plugins page, and set the path of the “directory.jasper.report” property to the place where you will hold your reports.

Thank you so much. This solved the problem. The attribute “directory.jasper.report” should be set in the server. Thanks!

Now I have another question. I can see the report and the columns already, however, some columns values are displaying records keys/code because it is supposed to use the Servoy valueList for displaying and mapping the value.

Does Servoy have a feature on changing the foundset’s column data from code to the value in the valueList? Just would like to know.

Thanks for the help!

Not sure about that.
Perhaps Tom would have some answers as he is our most distinguished JasperReport expert :)

What I know you could use is relations.

So instead of using the fk of the lookup you are using in Servoy, try setting a relation and then use this relation to point to the label…

For example:

  • suppose you have an order table, with an id_order_type which is the fk of an order_type table.
  • now define a relation, say ‘order_to_order_type’ from order to order_type, with id_order_type = id_order_type.
  • supposing you have a label column in your order_type table, you could use:
order_to_order_type.label

as the dataProvider of your field in JasperReport.

Don’t know if that’s clear enough but that way will work for sure.

ptalbot:
Not sure about that.
Perhaps Tom would have some answers as he is our most distinguished JasperReport expert :)

What I know you could use is relations.

So instead of using the fk of the lookup you are using in Servoy, try setting a relation and then use this relation to point to the label…

For example:

  • suppose you have an order table, with an id_order_type which is the fk of an order_type table.
  • now define a relation, say ‘order_to_order_type’ from order to order_type, with id_order_type = id_order_type.
  • supposing you have a label column in your order_type table, you could use:
order_to_order_type.label

as the dataProvider of your field in JasperReport.

Don’t know if that’s clear enough but that way will work for sure.

I understand. I should use Relations instead of valueLists. Thanks!

Cheers!

Patrick’s advice is very good about using relations to get at the “value list” equivalent. This does mean that you will have extra tables in your solution of course - and the bother of maintaining them. However, the jasper report will pick them up and of course you can always modify them within the jasper report to, perhaps, have different format for your report compared to the table value.
For example if you have a table value of “ACTIVE” “INACTIVE” “DEAD” then you could change these in the report to “Customer is active” “Customer is not active” “Customer NOT allowed to place orders” or of course whatever else you prefer…

It is always a good idea to check the reports directory prior to attempting to use the plugin. If it is null then you pop up an error message indicating that there is a software error and you should be notified to come and fix it!

ptalbot:
Why don’t you use the jasper file directly then if it’s compiled in iReport?
I don’t know if this will solve further problems but using the jrxml in Servoy just adds the overhead of compilation to your solution, so you could avoid it using the jasper file directly in your runReport() method.

my 2 cents :)

Hi,

I remember your post above regarding bypassing JRXML compilation. I need to manipulate the number of columns to be printed. Can this be done without modifying the JRXML?

I was planning to perform the following tasks to print some reports:

  1. parse predefined JRXML file using readXMLDocumentFromFile
  2. perform some updates on the number of field elements
  3. compile the JRXML and pass it to Jasper Reports through plugin

Cheers,
erikd

I’m afraid this cannot be done otherwise.
Unless you are using the VelocityReport plugin! ;)

Hi erik

what i understand is that you want to do different kind of reporting in the same report:

for exemple Detail band with 3 or 4 column depending of parameters that are sent from Servoy.

In jasper you have different solution to accomplish that:
First Solution:create different report (the most simple and ugly, difficult to maintain, like duplicating pieces of code)

Second Solution the good one:
Look at the sample code supply by servoy in the plug-in to send parameters to jasper with notation {parameter1:value, parameter2:value,etc…}

You could so create parameters (that will by filled later by servoy) in your report in the parameters node (for exemple withDetail boolean Type with default value =false and prompt unchecked)
Then you can use the power of jasper conditional printing on your label or field or band or everything using the object property ‘Print when Expression’ that you fill with $F{withDetail}==true or $F{withDetail}==false according to your needs.

then in you case you will get a servoy code like that

var _withdetail=true
var _myreportname='filenamewithoutpath.jrxml'
plugins.jasperPluginRMI.runReport(controller.getServerName(),myreportname,null,'view',{withDetail: _withDetail});

ps: i always declare my parameter values in variable before to be sure that they have the good type sent to jasper for exemple a integer parameter in jasper i declare var _myidforjasper = parseInt(orderid)

hope that can help

erdione:
Hi erik

You could so create parameters (that will by filled later by servoy) in your report in the parameters node (for exemple withDetail boolean Type with default value =false and prompt unchecked)
Then you can use the power of jasper conditional printing on your label or field or band or everything using the object property ‘Print when Expression’ that you fill with $F{withDetail}==true or $F{withDetail}==false according to your needs.

Your understanding is correct. Thanks for dropping this solution.

I just hope column width and locationX will adjust properly. I will try this.

erikd:
I just hope column width and locationX will adjust properly.

Unfortunately, it won’t.
Which is one of the reasons I build VelocityReport in the first place, using html’s table with automatic or percentage widths.

ptalbot:

erikd:
I just hope column width and locationX will adjust properly.

Unfortunately, it won’t.
Which is one of the reasons I build VelocityReport in the first place, using html’s table with automatic or percentage widths.

Can Velocity Report export files such as excel, and csv just like Jasper?

For CSV, you create your CSV yourself: it’s just text, so create a template, then use evaluateWithContext() or renderTemplate() to get the text back.

For XLS, more or less the same thing: use evaluateWithContext() or renderTemplate().
What I tend to do is write a html file with a table containing the data, then open the file forcing the mime-type to application/vnd.ms-excel. You can even embed Excel styles: simply create a file with the kind of style you want to reproduce, then in Excel, save as html. Then open it with a text editor and copy the css (and note down the classes to use in your html).

This is great.

Can we also print directly to the printer just like Jasper or show a native print dialog box?

erikd:
This is great.
Can we also print directly to the printer just like Jasper or show a native print dialog box?

I’m currently working on it ;)
@see Defect #1: Cannot print directly from the preview panel - VelocityReport Plugin - ServoyForge (you can watch the issue if you want, then you will be notified of any progress.

Basically there is a bug in the xhtmlrenderer lib that screws all the margins, but I have being doing some tests with the PDFRenderer project that allows me to print from a PDF generated in the background. I’m now working on trying to optimize the stuff, because right now, just like Jasper does, it is eating a significant amount of memory :(