Jump to content

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


thgr86

Recommended Posts

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.

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Popular Days

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...