lundi 13 juillet 2015

how to print Hash map from a bean in a jasper report

I'm working on generating the bills on my java application which are pdf file using jasper ireport. the file contains technically the attributes of the object Bill, this one has a Map and i need to iterate this one to get a dynamic list.

i've worked with arraylist but have no clue on how to iterate a map. pleas give me a hint.

Bill.java

public class Bill {

private Date billDate;
private String number;
private String subject;
private String biller;
private String billee;
private Date startDate;
private Date endDate;
private double tva;
private String paymentTransaction;
private Map<Double, Integer> quantityPerUnitPrice;

public Bill(Date billDate, String number, String subject, String biller, Map<Double, Integer> quantityPerUnitPrice,
        String billee, Date startDate, Date endDate, double tva, String paymentTransaction) {
    this.billDate = billDate;
    this.number = number;
    this.subject = subject;
    this.biller = biller;
    this.billee = billee;
    this.startDate = startDate;
    this.endDate = endDate;
    this.tva = tva;
    this.paymentTransaction = paymentTransaction;
    this.quantityPerUnitPrice = quantityPerUnitPrice;
}
//Getters and Setters
}

pdfService :

private byte[] print(File templateFile, Map parameters, Object objet) throws Exception {
        JasperReport jasperReport = (JasperReport) JRLoader
                .loadObject(templateFile);
        // - Execution du rapport
        List<Object> liste = (List<Object>) new ArrayList<Object>();
        liste.add(objet);
        JRBeanCollectionDataSource jdc = new JRBeanCollectionDataSource(liste);
        JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,
                parameters, jdc);
        return JasperExportManager.exportReportToPdf(jasperPrint);
    }

    @Override
    public byte[] generateBill(Object data) throws Exception {
        File templateFile = new File(PathUtils.getInstance().getClassesPath()
                + "/print/templates/"+ Constant.BILL_TEMPLATE);
        return print(templateFile,null,data);
    }

thank you so much

Aucun commentaire:

Enregistrer un commentaire