How do I list ireport java.util.List object data

0

I'm following java code.
When I run the report opens but does not seem to speed the data list

 

    public ArrayList generateCollection() {

        ArrayList
arrlist = new ArrayList();
        arrlist.add(new R2("Ankara"));
        arrlist.add(new R2("İstanbul"));
        arrlist.add(new R2("İzmir"));
        arrlist.add(new R2("Tokat"));
        arrlist.add(new R2("Kayseri"));


        return arrlist;
    }

    private class R2 {
        private String speed;

        public R2(String il) {
            super();
            this.speed = il;

        }

        public void setAdi(String adi) {
            this.speed = adi;
        }

        public String getAdi() {
            return speed;
        }
    }


    public void openReport(ActionEvent act) {
        Map
parameters = new HashMap();
        parameters.put("name", "myName");
        parameters.put("age", 21);
        parameters.put("speed", generateCollection());
        List masterList = new ArrayList();
        masterList.add(parameters);
        try {
            fillReport("D:\\workspace\\jasperReports\\jasperExample.jasper", parameters, masterList);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    public void fillReport(String repPath, Map
jasperParameter, List list) throws Exception {
        ReportUtils ru = new ReportUtils();
        Connection conn = null;
        try {

            JRDataSource jrDataSource = new JRBeanCollectionDataSource(list);
            HttpServletResponse response = ru.getResponse();
            ServletOutputStream out = response.getOutputStream();
            response.setHeader("Cache-Control", "max-age=0");
            response.setContentType("application/pdf");
            BufferedInputStream fs = new BufferedInputStream(new FileInputStream(repPath));
            JasperReport template = (JasperReport)JRLoader.loadObject(fs);
            template.setWhenNoDataType(WhenNoDataTypeEnum.ALL_SECTIONS_NO_DETAIL);
            JasperPrint jrPrint = JasperFillManager.fillReport(template, jasperParameter, jrDataSource);
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            JasperExportManager.exportReportToPdfStream(jrPrint, baos);
            out.write(baos.toByteArray());
            out.flush();
                    out.close();
            FacesContext.getCurrentInstance().responseComplete();
        } catch (Exception jex) {
            jex.printStackTrace();
        } finally {
            conn.close();
        }
    }
,>
,>
,>

//////////////////////////////////////

 

Thanks.

thgr86's picture
5
Joined: Apr 15 2013 - 12:27am
Last seen: 4 years 3 months ago

0 Answers:

No answers yet
Feedback