0

I cant understand why my code are not running all the time. I am opening a jasper report but for first 4 opening times the report is cached or code are not executing (Code in the new StreamResource are not executing first 4 times). new StreamResource.StreamSource() are running only at 5 time WHY ? The first 4 times i got the old,cached,temp or i event dont know what a pdf file with old params.

maybe someone know the issue ?

public static void open(final String fileName, final HashMap<String, Object> data ) {
    mylog.pl("@@@ Param's print @ open Report: Filename:" + fileName);
    try {
        Iterator<?> i = data.keySet().iterator();
        while (i.hasNext()) {
            String id = i.next().toString();
            String value = (data.get(id) != null) ? data.get(id).toString() : "null";
            mylog.pl(" id: " + id + " value: " + value);
        }
    } catch (Exception e) {
        e.printStackTrace();
        mylog.pl(e.getMessage());
    }
    StreamResource.StreamSource source = null;
    source = new StreamResource.StreamSource() {
        public InputStream getStream() {
            byte[] b = null;
            InputStream reportStream = null;
            try {
                reportStream = new BufferedInputStream(new FileInputStream(PATH + fileName + JASPER));
                b = JasperRunManager.runReportToPdf(reportStream, data, new JREmptyDataSource());
            } catch (JRException ex) {
                ex.printStackTrace();
                mylog.pl("Err @ JR" + ex.getMessage());
            } catch (FileNotFoundException e) {
                e.printStackTrace();
                Utils.showMessage(SU.NOTFOUND);
                return null;
            }
            return new ByteArrayInputStream(b);
        }
    };
    StreamResource resource = null;
    resource = new StreamResource(source, fileName + PDF);
    resource.setMIMEType("application/pdf");
    Page p = Page.getCurrent();
    p.open(resource, "Report", false);
}

1 Answers1

0

Here is the answer

I all the time used resource.setCacheTime(0); but really needed resource.setCacheTime(1000); because

In theory <= 0 disables caching. In practice Chrome, Safari (and, apparently, IE) all ignore <=0.

Community
  • 1
  • 1