B4J Library jJasperReports Library

Hi. I want to share this jJasperReports library with the community.
It needs several libraries to work. I provided a link: download
---More libraries needed (missing from the first link): download
You also need to download databases jdbc drivers: sql jdts, mysql and oracle
New Link (All jar files are included in this link): Download
All jars need to be placed in Additional Libraries folder.
In the B4J project you need to add a jar file: #AdditionalJar: itext-2.1.7.js1
Library files and a small example is provided.
Please feel free to test the library.
Note: for some reason when using SubReports, the compiled (.jasper) files need to be in the same level as the app jar file. XML Reports (.jrxml) can be in any other folder different from the app jar file. (e.g. if report.jrxml is in File.DirApp & "/reports" then all compiled (.jasper) subreports need to be in File.DirApp. In the example provided .jrxml and .jasper are in the same level as jaspertest.jar.

v1.00 - Release
v1.10 - SQLite support added. MySQL useSSL variable added.
v1.12 - Changed the way the JasperViewer works. Now you can set the form to full screen, use the default size and location or set a specific size and location.
v1.13 - Added method PrintDirectlyToPrinter.
v1.20 - Access support added via uCanAccess jdbc driver. Note: When creating reports in Jaspersoft Studio you need to add all jar files that ucanaccess needs. The metadata won't work but you can create a query and it will work.
v1.22 - Added functions to export report to XLS and XLSX. Note: need 2 more jar files: download. Copy them into Additional Libraries folder.
v1.24 - Added function Print3 to be able to show reports without a Data Source.

------------------------------------------

NEW VERSION 2.00
Special thanks to Num3 for testing this library and helping me getting it done.

Instructions:
1. Libraries needed: Donwload
2. Place all jars in Additional Libraries folder
3. Specify in B4J project with #AdditionalJar: the database that is going to be used. (e.g. #AdditionalJar: mysql-connector-java-5.1.49-bin)
a. If using ucanaccess-5.1.0 database please add these in addition to #AdditionalJar: ucanaccess-5.0.1:
- #AdditionalJar: commons-lang3-3.8.1
- #AdditionalJar: commons-logging-1.2
- #AdditionalJar: hsqldb-2.5.0
- #AdditionalJar: jackcess-3.0.1

v2.00 - Same functionality as v1.24 but based on jasperreports-6.17.0. Previous v1.24 was based on jasperreports-6.7.1.
 

Attachments

  • mainform.png
    mainform.png
    8.1 KB · Views: 1,536
  • jrxml_exported_to_pdf.png
    jrxml_exported_to_pdf.png
    53.9 KB · Views: 1,520
  • jrxml_subreports.png
    jrxml_subreports.png
    53.6 KB · Views: 1,621
  • jrxml_single_report.png
    jrxml_single_report.png
    16.7 KB · Views: 1,542
  • jJasperReports.zip
    10.2 KB · Views: 849
  • sqlite_report.png
    sqlite_report.png
    35.1 KB · Views: 1,362
  • jaspertest.zip
    2.8 KB · Views: 897
  • jJasperReports - 1.24.zip
    17.4 KB · Views: 570
  • jJasperReports - 2.00.zip
    17.6 KB · Views: 450
Last edited:

Xfood

Expert
Licensed User
yes, he shows them to me, but he doesn't let me download the files., I downloaded the single files by searching on google, do you have any sample reports to start with? I find this tool truly fantastic
 

Juan Marrero

Active Member
Licensed User
Longtime User
I'll be changing the links to dropbox or something. Apparently there is a download limit of shared files in google drive free. I'll let you know when I'm done.
 

Xfood

Expert
Licensed User
Samples are in the first post. You have to create reports. I use JasperSoft Studio Community.
thanks, you could also attach the b4j example of the report as in the picture
 

Attachments

  • jrxml_subreports.png
    jrxml_subreports.png
    53.6 KB · Views: 228

Juan Marrero

Active Member
Licensed User
Longtime User
I could but they will be useless for you. The reports are linked to my databases so you won't be able to use them.
 

Xfood

Expert
Licensed User
I could but they will be useless for you. The reports are linked to my databases so you won't be able to use them.
an example with a small sqlite db, and a report similar to that?
it would be very useful to learn how to manage reports better
Thanks so much

p.s. the add-on library links from the first post still don't work for me.
 

Juan Marrero

Active Member
Licensed User
Longtime User
an example with a small sqlite db, and a report similar to that?
it would be very useful to learn how to manage reports better
Thanks so much
I don't remember if in the sample code there was a sqlite database. Will check.

p.s. the add-on library links from the first post still don't work for me.
I wrote about changing links to dropbox. Download times have been exceeded.
 

Juan Marrero

Active Member
Licensed User
Longtime User
great, it works Thanks. it would be nice to have some examples in b4j, I find this tool really good and professional
Just need to create a sqlite database with a single table with 2 or 3 columns. In JasperSoft you need to create a Data Adapter pointing to that sqlite database and then you will be able to add fields to the report and do a preview. Couldn't find the reports.
 

focus330

Member
Licensed User
Longtime User
Hello!

Very good work. I'm appreciating. But I have a problem: I have a report with an image. It may contain an image if a boolean field is true and another if false, This is the code in Jasper report
B4X:
$F{level}.toString().equals("true") ? $P{checkboxOK} : $P{checkboxNOK}
It works fine with Preview but when I call from B4j I have this error:

B4X:
net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file:
1. The type java.lang.CharSequence cannot be resolved. It is indirectly referenced from required .class files
value = ((java.lang.Object)field_level.getValue()).toString().equals("true") ? ((java.lang.String)parameter_checkboxOK.getValue()) : ((java.lang.String)parameter_checkboxNOK.getValue()); //$JR_EXPR_ID=16$

what can I do? It seems a class is necessary.

Thanks
 

Juan Marrero

Active Member
Licensed User
Longtime User
Hello!

Very good work. I'm appreciating. But I have a problem: I have a report with an image. It may contain an image if a boolean field is true and another if false, This is the code in Jasper report
B4X:
$F{level}.toString().equals("true") ? $P{checkboxOK} : $P{checkboxNOK}
It works fine with Preview but when I call from B4j I have this error:

B4X:
net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file:
1. The type java.lang.CharSequence cannot be resolved. It is indirectly referenced from required .class files
value = ((java.lang.Object)field_level.getValue()).toString().equals("true") ? ((java.lang.String)parameter_checkboxOK.getValue()) : ((java.lang.String)parameter_checkboxNOK.getValue()); //$JR_EXPR_ID=16$

what can I do? It seems a class is necessary.

Thanks
What are checkboxOK and checkboxNOK? Are those parameters for what? For images to appear in report, you need to specify the full path of the image. I'm going to need more info on this. Java version, JasperSoft version (if using iReport can't help you there), the report itself, etc..
 
Last edited:

Juan Marrero

Active Member
Licensed User
Longtime User
Hello!

Very good work. I'm appreciating. But I have a problem: I have a report with an image. It may contain an image if a boolean field is true and another if false, This is the code in Jasper report
B4X:
$F{level}.toString().equals("true") ? $P{checkboxOK} : $P{checkboxNOK}
It works fine with Preview but when I call from B4j I have this error:

B4X:
net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file:
1. The type java.lang.CharSequence cannot be resolved. It is indirectly referenced from required .class files
value = ((java.lang.Object)field_level.getValue()).toString().equals("true") ? ((java.lang.String)parameter_checkboxOK.getValue()) : ((java.lang.String)parameter_checkboxNOK.getValue()); //$JR_EXPR_ID=16$

what can I do? It seems a class is necessary.

Thanks
Or maybe try this:
B4X:
($F{level}.equals(Boolean.TRUE.toString())) ? $P{checkboxOK} : $P{checkboxNOK}
But remember to create a parameter for the path of the image and use the function in JasperReports Library to assign the image's path to that parameter.
 

focus330

Member
Licensed User
Longtime User
1 Yes: CheckboxOK and CheckboxNOK are parameters for images.
2 TIBCO Jaspersoft® Studio 6.16.0
3 Using the grammar you suggested ...
B4X:
($F{level}.equals(Boolean.TRUE.toString())) ? $P{checkboxOK} : $P{checkboxNOK}
it runs fine. Thanks very much
SOLVED
 

Juan Marrero

Active Member
Licensed User
Longtime User
1 Yes: CheckboxOK and CheckboxNOK are parameters for images.
2 TIBCO Jaspersoft® Studio 6.16.0
3 Using the grammar you suggested ...
B4X:
($F{level}.equals(Boolean.TRUE.toString())) ? $P{checkboxOK} : $P{checkboxNOK}
it runs fine. Thanks very much
SOLVED
Perfect. I spent some time looking in forums about your error and found that suggestion. Glad it worked.
 

Num3

Active Member
Licensed User
Longtime User
Any chance this library can be updated to use the latest jasperreports_6.17.0.final.jar build?
It is already 10 revisions behind :\

And the:
B4X:
<textField textAdjust="StretchHeight">
Is not supported in this old version

I tried the renaming trick, but there are conflicts...
 
Last edited:

Juan Marrero

Active Member
Licensed User
Longtime User
Any chance this library can be updated to use the latest jasperreports_6.17.0.final.jar build?
It is already 10 revisions behind :\

And the:
B4X:
<textField textAdjust="StretchHeight">
Is not supported in this old version

I tried the renaming trick, but there are conflicts...
Will put it on schedule. Don't have an estimate date. My 3yr old consumes most of my free time.
 

cjpryor

Active Member
Licensed User
Posting here because what I have to offer is relevant to this post. There is a way to solve the subreport location problem. You can add a parameter to the main report that holds the subreport directory and then add that to the subreport configuration in the main report. You can set the default value to your development directory (for testing in the JasperSoft development environment) and then pass in the deployment directory from your code at run time.

Here's how I did it.

1. Add SUBREPORT_DIR parameter to main report

DirParam.png


2. Set default value to your development directory

DirParamDefault.png


3. In main report, configure subreport to use this parameter

SubRptConfig_1.png


SubRptConfig_2.png


4. In your code set this parameter to the deployed subreport directory

B4X:
        jasper.InitializeParameters
        '...
        '... I have additional parameters here that are not relevant to this illustration
        '...
        jasper.AddParameter("SUBREPORT_DIR", File.DirData("nmcollector/Reports") & "\")

5. Of course, make sure the subreport is in the directory. On a related note, I do not like to compile the subreport from the code. Instead, I compile it from Jaspersoft and deploy the compiled report to the deployment directory. Then I just call the main report and it in turn calls the compiled subreport.
 

Attachments

  • Dir_Param.png
    Dir_Param.png
    145.2 KB · Views: 221
  • Dir_Param.png
    Dir_Param.png
    145.2 KB · Views: 200
  • SubRptConfig_1.png
    SubRptConfig_1.png
    202.1 KB · Views: 181
  • DirParam.png
    DirParam.png
    145.2 KB · Views: 177

Juan Marrero

Active Member
Licensed User
Longtime User
Posting here because what I have to offer is relevant to this post. There is a way to solve the subreport location problem. You can add a parameter to the main report that holds the subreport directory and then add that to the subreport configuration in the main report. You can set the default value to your development directory (for testing in the JasperSoft development environment) and then pass in the deployment directory from your code at run time.

Here's how I did it.

1. Add SUBREPORT_DIR parameter to main report

View attachment 116738

2. Set default value to your development directory

View attachment 116741

3. In main report, configure subreport to use this parameter

View attachment 116739

View attachment 116740

4. In your code set this parameter to the deployed subreport directory

B4X:
        jasper.InitializeParameters
        '...
        '... I have additional parameters here that are not relevant to this illustration
        '...
        jasper.AddParameter("SUBREPORT_DIR", File.DirData("nmcollector/Reports") & "\")

5. Of course, make sure the subreport is in the directory. On a related note, I do not like to compile the subreport from the code. Instead, I compile it from Jaspersoft and deploy the compiled report to the deployment directory. Then I just call the main report and it in turn calls the compiled subreport.
Very good aproach!!
 
Top