I want to generate a bill using jasper reports of different items. For this, I have defined some String arrays which I want to display in the bill as a List of items.
My code for filling the jasper report is given below
System.out.println("In printing servlet");
String [] prod = request.getParameterValues("prodn[]");
String [] pkgdate = request.getParameterValues("pkgdate[]");
String [] manufact = request.getParameterValues("manufact[]");
String [] exp = request.getParameterValues("exp[]");
String [] batch = request.getParameterValues("batch[]");
String [] unit = request.getParameterValues("unit[]");
String [] qty = request.getParameterValues("qty[]");
String [] subtot = request.getParameterValues("subtot[]");
ArrayList<String> prodname = new ArrayList<String>();
ArrayList<String> packagedate = new ArrayList<String>();
ArrayList<String> manufactdate = new ArrayList<String>();
ArrayList<String> exipry = new ArrayList<String>();
ArrayList<String> batchno = new ArrayList<String>();
ArrayList<String> unitprice = new ArrayList<String>();
ArrayList<String> quantity = new ArrayList<String>();
ArrayList<String> Subtotal = new ArrayList<String>();
Map<String, Object> param = new HashMap<String, Object>();
try {
JasperPrint jasperPrint =null;
InputStream is=this.getClass().getResourceAsStream("/com/medicam/servlets/Invoice.jrxml");
JasperReport jasperReport = JasperCompileManager.compileReport(is);
for(int i=0;i<prod.length;i++)
{
prodname.add(prod[i]);
packagedate.add(pkgdate[i]);
manufactdate.add(manufact[i]);
exipry.add(exp[i]);
batchno.add(batch[i]);
unitprice.add(unit[i]);
quantity.add(qty[i]);
Subtotal.add(subtot[i]);
System.out.println("Name :"+prod[i]+" Pkg date: "+pkgdate[i]+"Man :"+manufact[i]+" Expi: "+exp[i]+" Batch: "+batch[i]+" Unit: "+unit[i]+" Quan: "+qty[i]+" Sub:"+subtot[i]);
}
param.put("prodname", String.valueOf(prodname));
param.put("pkgdate", String.valueOf(packagedate));
param.put("manfdate", String.valueOf(manufactdate));
param.put("expdate", String.valueOf(exipry));
param.put("batch", String.valueOf(batchno));
param.put("unit", String.valueOf(unitprice));
param.put("qty", String.valueOf(quantity));
param.put("subtot", String.valueOf(Subtotal));
jasperPrint = JasperFillManager.fillReport(jasperReport, param, new JREmptyDataSource());
JasperViewer.viewReport(jasperPrint, false);
}
catch (Exception e) {
e.printStackTrace();
}
The Sring arrays are using to populate the ArrayList which are passed to the HashMap to fill my report. The HasMap Keys are the parameter names which are declared in Invoice.jrxml file The parameter names are given to textfiles like
<textField>
<reportElement x="-1" y="60" width="80" height="101" uuid="06fab25e-d80f-4535-8d85-1bea04dfca84"/>
<textElement textAlignment="Center"/>
<textFieldExpression><![CDATA[$P{prodname}]]></textFieldExpression>
</textField>
I want to print the LIST of items but I am getting the output as comma separated values in a single line.
Sample Output here and picture below.