Blank subreport in Jasper Reports - java

I'm trying to launch a report that I created in iReport which contains a main report and a subreport. In iReport, the subreport launches fine and contains data, however when I try to launch it from within my java code, the subreport is blank.
What I've done so far:
I have a String parameter in the main report called "SUBREPORT" that is used to define the path to the subreport. E.g. value: "E:\java\ReportLauncher\reports\test_subreport1.jasper"
The subreport expression in the main report is set to: $P{SUBREPORT}
The subreport connection expression is: $P{REPORT_CONNECTION}
I also have a subreport parameter defined called "INVOICE_NUMBER" that is set to $F{InviInvNo}, which maps to a field in the main report.
In my java code, I have:
HashMap<String, Object> paramHash = new HashMap();
paramHash.put("INVOICE_NUMBER", invoiceID);
paramHash.put("REPORT_CONNECTION", this.conn);
paramHash.put("SUBREPORT", subReportPath);
JasperPrint jasperprint = JasperFillManager.fillReport(this.reportPath, paramHash, this.conn);
The main report is created fine and is populated. The subreport area however is blank. Any thoughts for what I'm doing wrong?
Thanks in advance,
Andy.

Since you didn't mention anything about the subreport query:
If you are using the Detail Band in the subreport, then you will need a Data Query for the report.
In old iReport, from Data menu, choose Report Query and write your query here. If you want only one record (i.e. Detail band only one time) you can use a dummy table. Like:
SELECT 'a' FROM DUMMY
Otherwise, if you don't want to use the Detail Band, you have the option to view the other bands without using a query. From Edit menu, choose Report Properties, under More... tab, set the flag When no data to All Sections, no detail

Related

How to make a subreport that uses web service as the data source work in Jasper Reports

Can someone post a working example of how to define a subreport using web service as the datasource?
I am reading this:
http://community.jaspersoft.com/project/web-service-data-source
Under the section "SubReport and Additional Datasets", I need to cater the scenario for (2):
you have a main resultset that you wish to loop, and for each row you want to execute a new query (webservice call)
In the subreport configuration (or the dataset) specify not to use any connection at all (leave blank both the connection expression and the datasource expression. The only thing we'll have to do is passing some mandatory parameters for internal webservice datasource to work properly:
uriKeyauth
TypeKey
authParametersKey
languageKey
verbKey
I am not able to understand what to do here based on the above statements. These parameters are defined in the web service subreport. Am I supposed to pass them back to the main report? If so how am I supposed to do it in Jaspersoft Studio? I am using version 6.2. Even after I define these parameters in the main report, when I run preview, I get the error:
Caused by: net.sf.jasperreports.engine.JRException: Verb should be POST or GET . is not a valid verb
After struggling with this for quite a while, I found the following.
In my case, the default data adapter in the main report is JDBC. For each row returns from the SQL query, one particular column value is used as a GET parameter for the web service data adapter or WebServiceQuery.
I cannot make this work with subreport. However, I can get this to work with a dataset associated with a table.
A dataset using the web service data adapter has to be created. Parameters that are required for the GET parameters need to be defined in the dataset.
After the dataset is created, create a table or other elements using this dataset. Under the dataset tab in the table properties, define the parameters which should have the relevant field values (eg, $F{field1}).
The web service dataset also needs to connect to the main dataset. All this does is define the web service parameters: uriKey, authTypeKey, authParametersKey, languageKey, verbKey in the main report.
Once this is done, previewing the main report will also render the table with results obtained from the web service data adapter.
The steps to I use in Jasper Studio 6.3 are:
Create web service data adapter that your subreport will use.
Using the context menu, export the data adapter to a file in your workspace.
In the properties of the report used as the subreport, set the default data adapter to the exported file.
Pass the appropriate parameters from the master report to the subreport.

Can't use Row Data Resulted from Scripted DataSet

Performing a test with BIRT I was able to create a report and render it in PDF, but unfortunatelly I'm not getting the expected result.
For my DataSource I created a Scripted DataSource and no code was needed in there (as far as I could see the documentation to achieve what I'm trying to do).
For my DataSet I create a Scripted DataSet using my Scripted DataSource as source. In there I defined the script for open like:
importPackage(Packages.org.springframework.context);
importPackage(Packages.org.springframework.web.context.support);
var sc = reportContext.getHttpServletRequest().getSession().getServletContext();
var spring = WebApplicationContextUtils.getWebApplicationContext(sc);
myPojo = spring.getBean("myDao").findById(params["pojoId"]);
And script for fetch like:
if(myPojo != null){
row["title"] = myPojo.getTitle();
myPojo = null;
return true;
}
return false;
As the population of row will be done on runtime, I wasn't able to automatically get the DataSet columns, so I created one with the following configuration: name: columnTitle (as this is the name used to populated row object in fetch code).
Afterwards I edited the layout of my report and added the column to my layout.
I was able to confirm that spring.getBean("myDao").findById(params["pojoId"]); is executed. But my rendered report is not showing the title. If I double click on my column label on report layout I can see there that expression is dataSetRow["columnTitle"] is it right? Even I'm using row in my fetch script? What am I missing here?
Well, what is conctractVersion?
It is obviously not initialized in the open event.
Should this read myPojo.contractVersion or perhaps myPojo.getContractVersion()?
Another point: Is the DS with the column "columnTitle" bound to the layout?
You should also run your report as HTML or in the previewer to check for script errors.
Unfortunately, these are silently ignored when generating the report as PDF...
The problem was the use of batik twice (two different versions), one dependency for BIRT and other for DOCX4J.
The issue is quite difficult to identify because there is no log output rendering PDF files.
Rendering HTML I could see an error message which I could investigate and find the problem.
For my case I could remove the DocX4j from maven POM.

Java Crystal Report SDK - Report & SubReport

I'm trying to generate a report using Crystal Report SDK in Java composed by a main report and a subreport.
I do want to generate the report only if there is something returns by my stored procedure and for doing that I execute the proc manually and launch the report generation only if my ResultSet != null.
But, my subreport has to be generated through Crystal.
I use the setTablesDatasource() method for my main report for using my ResultSet
For my subreport:
_ I use the setTableslocation() for getting the values and generating the report through crystal
_ I set all the parameters needed in the ParameterFieldController of my subreport.
However, I'm getting this error in my console :
Missing parameter values.---- Error code:-2147217394 Error code
name:missingParameterValueError
Even though the subreport's parameters are correctly setted.
If I generate my report with no subreport or with report and no needed parameter, the generation is just fine.
Am I setting my parameters in a wrong way ?
After trying a lot of stuff for integrating my subreport without using another ResultSet, here is the way for setting the parameters for the subreport :
You have to use the ParameterFieldController of the main report and not the one of the subreport... Logic.
ParameterFieldController paramFieldController =
rptClientDoc.getDataDefController().getParameterFieldController();
paramFieldController.setCurrentValue(subreport_name, parameter_name,
parameter_value);
And now, it works just fine !

Subreport trouble in iReport 0.4.1

I am using iReport 0.4.1 and JasperReports 0.6.3, and I'm facing the trouble trying to generate a subreport:
I set in Java code .jasper subreport path, it's correct, but putting wrong path for test, no errors happen;
In subreport, putting a field for test, again no errors happen (i.e., the subreport is not accessed...);
I tried to access subreport list by two ways: as parameter and as a main report bean field (it's not the case: in fact I have two not-related reports to print in the same page, so that's why the subreport);
In almost all tries, when didn't happen error, appears a blank where subreport's data had to be
PS.: I put the subreport in Detail band, with main report data.
Could somebody help me? - both reports code below.
PS 2: I can't change versions, it's a new report in an existent structure, with this iReport and JasperReports version.
Java report calls:
parameters.put("subreportPath", projetoPath + "<CAMINHO>\\" + "xxxzz.jasper"
.................
parameters.put("ListaComparativoSaldos", listaSubreport);
//ABAIXO: nao funcionou
//parameters.put("ListaComparativoSaldos", new JRBeanCollectionDataSource(listaSubreport));
.................
return JasperFillManager.fillReport(is, parameters, new JRBeanCollectionDataSource(data));

Set sizes of report bands in jasper report

Let me know how to set the height of Detail band programmaticaly in iReport in swing application? That means, when the data filled in Detail band, then footer should be next, and no any white space.In my report when the few data filled in report, there is more white space till the page bottom.I want to remove that white space and set the column footer just after the last data in detail band.Thank you
You can set band via JasperReports API using JRDesignBand class:
public void JRDesignBand.setHeight(int height)
or via DynamicJasper API using AbstractLayoutManager class
protected void AbstractLayoutManager.setBandFinalHeight(net.sf.jasperreports.engine.design.JRDesignBand band)
- Sets the band's height to hold all its children
You can see samples:
with help of JasperReports API
and with help of DynamicJasper API
You can also solve your problem without programming using only iReport. Try to set ignore pagination report property value to true:
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" ... isIgnorePagination="true"
You can also view this link.
JasperReports API allows to set this property using JasperDesign class :
public void JasperDesign.setIgnorePagination(boolean ignorePagination)
- Sets the value of the ignore pagination flag
JasperDesign jasperDesign = JRXmlLoader.load(file);
JRDesignBand band = (JRDesignBand) jasperDesign.getPageFooter();
band.setHeight(SIZE);
You can change getPageFooter to another band...

Categories

Resources