Dear Sirs

I am using Joget version 3 and I have installed the Jasper reports server. but i need to perform the following:-

1. How can I pass dynamic parameters between the( Joget userview or Joget web console) and the JasperReport. for example i need to pass two parameters (date from & date to) from the joget userview to JasperReport and then display the report which will display info about all the completed processes within these dates.

i tired my best to find relevant documentation but i fail,, bearing in mind that this is a high priority requirement from my client.

Best Regards

  • No labels

5 Comments

  1. Hi John,

    There is a JasperReports Userview Menu in our 3.1-BETA release. But it still very basic and incomplete feature. This extra feature is not able to integrate with JasperReport server as well.

    For temporary solution, you may put it in an iframe if no authentication is required. To pass parameter, you may try make use of our Hash Variables.

    Hope this help.

    Best regards. 

  2. Hi John,

    If you are looking to generate really fancy/dynamic reports, here is my solution, this is what I did. This is going to be mixture of Joget and standard Java Servlet.

    1. Create a form in Joget, this form will have those parameter selections which will be passed to your jasper report. (see the attachment of my application form)
    2. Create a Java Servlet application, which will do the Jasper stuff (mean all of your jasper report stuff), and copy your servlet application in the webapp folder of tomcat.

    3. Now insert a custom HTML element in your joget form and make a call to your jasper report app. Following is the code from my app.

    <script>
    $(document).ready( function(){
        $("#submit").click( function(){
    		var fromDate = $("input[name=fromDate]").val();
    		var toDate = $("input[name=toDate]").val();
    		var nameFrom = $("input[name=nameFrom]").val();
    		var nameTo = $("input[name=nameTo]").val();
    		var reportType = $('input[name=reportType]:checked').val();
    		var reportUrl = "/jasperApplication/generateReport?fd="+fromDate+"&ed="+toDate+"&nf="+nameFrom+"&nt="+nameTo+"&rt="+reportType;
    		window.location = reportUrl;
    		return false;
        });
    });
    </script>

    Once you hit the submit button, It will pass the parameters to jasper servlet application and it will let you download the generated report.

    I am also attaching the piece of Java Code which I used to generate the PDF report.

    private void exportToPdf(String storagePath, HttpServletResponse response, Connection connection){
    	String filename = "MyReport.pdf";
    	try {
    		ServletOutputStream servletOutputStream = response.getOutputStream();
    		String jasperFile = "MyReport.jasper";
    		File reportFile = new File(storagePath+"/"+jasperFile);
    		Map jasperMap = new HashMap();
    
    		// Here I am passing the whole query to report as parameter, as there were lot of checking on the parameters
    		// You can ignore this, and just pass the required parameters to the report
    		String reportQuery = prepareQuery(dateFrom,dateTo,nameFrom,nameTo);
    
    		//jasperMap.put("reportQuery", reportQuery);
    
    		jasperMap.put("param1", param1);
    		jasperMap.put("param2", param2);
    
    		byte[] runReportToPdf = JasperRunManager.runReportToPdf(reportFile.getPath(), jasperMap, connection);
    
    		servletOutputStream.write(runReportToPdf, 0, runReportToPdf.length);
    		response.setContentType(APPLICATION_PDF);
    		response.setHeader( "Content-Disposition", "attachment; filename=\"" + filename + "\"" );
    		response.setContentLength(runReportToPdf.length);
    	} catch (Exception e) {
    		Logger.getLogger(MyJasperClass.class.getName()).log(Level.SEVERE, null, e);
    	}
    }

    And your sql should be like this (inside the ireport)

    SELECT * FROM tablename
    WHERE 1=1 $P!{param1} $P!{param2}
    ORDER BY colName;
    
    OR
    
    SELECT * FROM tablename
    WHERE 1=1 colName=$P!{param1}
    ORDER BY colName;  

    Hope this will help.

    1. thanks for the reply ,, but i am unable to know how i can add a new "submit" button to my form.

  3. How to generate PDF and  XLS or CSV report ? 

    Thank you ..

    1. Hi there,

      In the (recent latest Joget) configuration of JasperReports Reporting Integration Userview Menu, you can select to export the report in PDF or Excel.

      Hope this helps.

      Thanks.