Pass as parameter to Jasper an Object

1

I'm trying to create a report, now it's already generating, but only when I step into JasperPrint's JREmptyDataSource ().

JasperPrint impressoraJasper = JasperFillManager.fillReport("D:/Edital.jasper", parametros, new JREmptyDataSource());

It creates the edital but with all null fields. So I tried to create an Array with my Bean, but I did not succeed, because inside iReport I used 3 classes with inner joins. And I can not pass 3 different beans.

In my ManagedBean, I have an editable object already filled in, and my report only receives a single parameter, which is the ID of this edict. Do I really need a dataSource? He's having a problem with him. How do I pass just this Jasper ID and generate it?

My code:

public void imprimirRelatorio() throws IOException, ParseException {

    HashMap parametros = new HashMap();
    parametros.put("ID_EDITAL", edital.getIdEdital());
    FacesContext facesContext = FacesContext.getCurrentInstance();

    try {

        Edital[] beanArray = new Edital[1];
        beanArray[0] = edital;  

        JRBeanArrayDataSource dsColecao1 = new JRBeanArrayDataSource(beanArray, false);

       JasperPrint impressoraJasper = JasperFillManager.fillReport("D:/Edital2.jasper", parametros, dsColecao1);

        File pdf = new File("relatorio2.pdf");
        pdf.createNewFile();
        FileOutputStream arquivo = new FileOutputStream(pdf);
        System.out.println(pdf.getAbsolutePath());

        JasperExportManager.exportReportToPdfStream(impressoraJasper, arquivo);

        arquivo.flush();
        arquivo.close();  

    } catch (JRException e) {
        e.printStackTrace();
    }          
}

EDIT: I made a report that uses only one bean (without inner joins), I placed this bean in an array with a single position and it worked. Now how do I put the rest of the beans?

    
asked by anonymous 31.01.2015 / 23:47

0 answers