Reputation: 13492
I am using
filename.jrxml
file to create a simple report with
itext4.8.0
and it is working fine but i am passing parameter like this.
$P{userId}]
Now i will want to use same
filename.jrxml
With java code How can i achieve this ? My main concern is how can we pass parameter value as in ireport when i am running report in ireport it is opening popup for parameter and i am entering value .But in Java code how can pas that parameter?
Note:-I dont want to pass connection with reports.
Upvotes: 0
Views: 1653
Reputation: 203
Download jasperreport engine
final Map<String,Object> parameter = new HashMap<String, Object>();
parameter.put("userId", 1l);
JasperFillManager.fillReport("filename.jasper", parameter, getData());
// set your own params for this method
public JRDatasource getData() {
// initialize a collection of Objects
// Oh yes the query
final Query query = getQuery("from SomeObject");
final List<SomeObject> collection = (List<SomeObject>)query.list();
return new JRBeanCollectionDataSource(collection);
}
Another possibility
JasperFillManager.fillReport(jasperReport, parameter, connection);
Upvotes: 0