1 Reply Latest reply on Apr 25, 2005 2:50 PM by logicfish

    how to open new window to display a stream?

    greg_gl

      I'm using nukes and JasperReports.

      I have a nukes module that create a jasper reports.
      I do not want save the report on the server.

      So i just have a stream (a byte array) and i want to display this in a new window.
      How can I o that? It is possible to do that?

      public class Report extends ModuleSupport {
      
       public void report (Page a_page) throws SQLException {
       String l_fileName = "report.jrxml";
       Map l_param = new HashMap();
       Connection l_con = getConnection();
      
       JasperDesign design = JRXmlLoader.load(l_fileName);
       JasperReport report = JasperCompileManager.compileReport(design);
       JasperPrint print = JasperFillManager.fillReport(report, l_param, l_con);
      
       // the array that i want to display in a new window
       byte [] pdf = JasperExportManager.exportReportToPdf(print);
       }
      }
      


      Thanks.

        • 1. Re: how to open new window to display a stream?
          logicfish

          I have done something similar with my module which can display images.
          To display content outside of the nukes theme I override the `process' method instead of using the `op(Page p)' style.
          The url changes to `/nukes/modules/yourmodule/yourresource'
          and you parse the url inside the method and then setup the binary resource.
          Heres part of my code:

           public void process(Signature signature, NukesRequest req,
           NukesResponse resp) {
           if (signature instanceof ModuleResourceSignature) {
           ModuleResourceSignature mrs = (ModuleResourceSignature) signature;
           String id = mrs.getPath();
           Resource res = null;
           if (id.startsWith("/report")) {
           byte[] bin = .......;
           res = new ByteArrayResource("image/jpeg", bin); // yours would be pdf
           res.setName("whatever.jpg");
           resourceManager.add("/report/" + name, res);
           resp.setResult(new ResourceResult(res));
           } else {
           res = getResource(id);
           if (res != null) {
           resp.setResult(new ResourceResult(res));
           } else {
           resp.setResult(CodeResult.CODE_404);
           }
           } else {
           super.process(signature, req, resp);
           }
           }
          

          To open in a new window use javascript in the href url.
          Hope this helps.