Reputation: 31
I'm developing a Java project with JasperReports(v.4.0.6) and DynamicJasperReports(v.4.0.1). I have generated a custom .jrxml with the most recent iReport plugin for Eclipse.
In my .jrxml report, I define two parameters which will be filled by the Java program according to some input given by the user.
<parameter name="ReportTitle" class="java.lang.String"/>
<parameter name="DataFile" class="java.lang.String"/>
Then, as this tutorial states, and since I want to maintain a couple of parameters predefined, I invoke the setTemplate() method from my code.
String table_template = "report_templates/TableTemplate.jrxml";
Map<String, String> params;
...
DynamicReportBuilder drb = new DynamicReportBuilder();
drb.setTemplateFile(table_template, true, true, true, true);
DynamicReport dr = drb.build();
I pass the parameters to the template doing the following:
params.put("ReportTitle", "CustomTitle");
params.put("DataFile", "CustomSubtitle");
However, when I genereate de report, these two fields appear blank, as if the DJ library hadn't save the places in which to insert the values beforehand. I don't get any other errors or exceptions.
I've tried downgrading the Jasper library to al older version, but to no avail either.
I'd appreciate if someone could give me some insight to what I am doing wrong.
Thanks in advance.
Upvotes: 3
Views: 2643
Reputation: 384
Having a paremeter already defined in the jrxml only means that in your custom expression you can get its value as
params.get("paramName")
Without prior registration ( drb.addParameter(...) )
You can always create a custom expression column and put a breakoint in the custom expression code and check the contents of the parameters map in runtime!
If you use the paremter outside DJ, say, a header or footer text, there should be not problem with it
Upvotes: 2