Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Bhavik Kama
how to preview jasper report withough saving the html or pdf file ?
December 24, 2012 8:55 PM
Answer

Bhavik Kama

Rank: Junior Member

Posts: 55

Join Date: September 23, 2012

Recent Posts

Following is my fucntion which am calling in my serveResource method in portletAction

 1 public String ajax_GenerateReportsforCampaignAdvertiseDateRangeWithCustomQuery(
 2                ResourceRequest request, ResourceResponse response,
 3                String str_camp_id) throws Exception {
 4       
 5   
 6            PortletContext pc = request.getPortletSession().getPortletContext();
 7            String Pathjrxml = pc
 8                    .getRealPath("/src_reports/Campaign_Advertise_DateRange_Report.jrxml");
 9            String pathjasper = pc
10                    .getRealPath("/src_reports/Campaign_Advertise_DateRange_Report.jasper");
11   
12            _report_path = pc.getRealPath("htmlreport/report");
13            _report_name = Calendar.getInstance().getTimeInMillis() + "";
14            _report_path = _report_path + _report_name;
15            
16            String str_start_date = request.getParameter("f_start_date");
17            String str_end_date = request.getParameter("f_end_date");
18            Date filter_start_date = null;
19            Date filter_end_date = null;
20            
21            List<CampaignReport> temp_campReportList = new ArrayList<CampaignReport>(
22                    8);
23   
24            log.info("ajax_Generate Reports For Campaign Advertise With Date Range Enter");
25            
26            /** Dateformat which will convert filter date string in to specified **/
27            
28            DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
29   
30            filter_start_date = dateFormat.parse(str_start_date);
31   
32            filter_end_date = dateFormat.parse(str_end_date);
33   
34            str_end_date = dateFormat.format(filter_end_date);
35   
36            log.info("Filter Start Date : " + filter_start_date);
37            log.info("Filter End Date : " + filter_end_date);
38   
39            ReportCustomQuery cust = new ReportCustomQuery();
40            String pathImage = request.getContextPath()
41                    + "/eMenuAdvertise-portlet/img/eMenu Logo_1.png";
42            temp_campReportList = cust.GetAdvertiseListByCampaignsForReports(
43                    Long.parseLong(str_camp_id), filter_start_date,
44                    filter_end_date, pathImage);
45   
46            
47   
48            System.setProperty("java.awt.headless", "true");
49       
50            JRBeanCollectionDataSource beanCollectionDataSource = new JRBeanCollectionDataSource(
51                    temp_campReportList);
52            System.out.println(" bean collection "
53                    + beanCollectionDataSource.getRecordCount());
54            System.out.println("Compile Start");
55   
56       
57   
58       
59   
60            JasperCompileManager.compileReportToFile(Pathjrxml, pathjasper);
61            JasperPrint jasperPrint = JasperFillManager.fillReport(pathjasper,
62                    new HashMap<String, Object>(), beanCollectionDataSource);
63   
64            log.info("Compile End");
65            log.info(" report path " + _report_path);
66            
67   
68            JasperExportManager.exportReportToHtmlFile(jasperPrint, _report_path
69                    + ".html");
70            JasperExportManager.exportReportToPdfFile(jasperPrint, _report_path
71                    + ".pdf");
72   
73            log.info("ajax_GenerateReports Leave");
74            return _report_name;
75        }


and the ajax call which call this method is following



 1    <script type="text/javascript">
 2        function GenerateReport(addToDo) {
 3            var camp_ID = document.getElementById('camp_id').value;
 4            var f_start_date = document
 5                    .getElementById('Start_validBeforeDatepicker').value;
 6            var f_end_date = document.getElementById('End_validAfterDatepicker').value;
 7            $.ajax({
 8                url : addToDo,
 9                data : {
10                    "camp_id" : camp_ID,
11                    "f_start_date" : f_start_date,
12                    "f_end_date" : f_end_date,
13                    "CMD" : camp_ID
14                },
15                type : "GET",
16                timeout : 20000,
17                dataType : "text",
18                async : false,
19                success : function(data) {
20   
21                    createRenderURL(data);
22   
23                }
24            });
25</script>



following is my creatRenderUrl javascript which creating dynamic resourceurl for newly created html file and then i am showing that html page in iframe as preview

 1 function createRenderURL(str_path,contextpath,resourceurl) {
 2       
 3       
 4   
 5        AUI().use('liferay-portlet-url', function(A) {
 6   
 7            var renderURL = Liferay.PortletURL.createRenderURL();
 8            renderURL.setParameter("jspPage", "/htmlreport/report" + str_path);
 9            renderURL.setPortletId("eMenuAdvertise_WAR_eMenuAdvertiseportlet");
10            
11            
12            var p= "<%=renderRequest.getContextPath()%>";
13            var downloadurl="/eMenuAdvertise-portlet/htmlreport/report"+ str_path+".pdf";
14            
15            var x=document.getElementById("outPopUp");
16            x.style.visibility="hidden";
17            
18            document.getElementById('reportpreview').src = "/eMenuAdvertise-portlet/htmlreport/report"+ str_path+".html";
19       
20            
21            $("#download").click(function () {
22               
23                DownloadFile(downloadurl,resourceurl);
24               
25   
26    });
27            
28             return downloadurl;
29            
30        });
31   
32    }


But what i want to do is how can i preview the preview of report withought saving any file?on the fly preview?

Please give me any guidance..
Nagendra Kumar Busam
RE: how to preview jasper report withough saving the html or pdf file ?
December 24, 2012 8:59 PM
Answer

Nagendra Kumar Busam

Rank: Liferay Master

Posts: 637

Join Date: July 7, 2009

Recent Posts

Bhavik Kama
RE: how to preview jasper report withough saving the html or pdf file ?
December 24, 2012 9:21 PM
Answer

Bhavik Kama

Rank: Junior Member

Posts: 55

Join Date: September 23, 2012

Recent Posts

i know about JasperViewer.viewReport (jasperPrint); but how can i make it execute with the ajax call?because ma all reports generation and jasperprint object created in my action class and if am doing JasperViewer.viewReport (jasperPrint); in action class then how can it shows me in my jsp page?
Nagendra Kumar Busam
RE: how to preview jasper report withough saving the html or pdf file ?
December 24, 2012 9:39 PM
Answer

Nagendra Kumar Busam

Rank: Liferay Master

Posts: 637

Join Date: July 7, 2009

Recent Posts

I think you have two options now

> one is set attributes needed to generate report using veiwReport() @ server side & generate report dynamically in jsp

> another option is (might be not the one exactly you are looking into), delete the report generated using html/pdf format once preview is displayed if you don't want that in local disk
Bhavik Kama
RE: how to preview jasper report withough saving the html or pdf file ?
December 24, 2012 9:50 PM
Answer

Bhavik Kama

Rank: Junior Member

Posts: 55

Join Date: September 23, 2012

Recent Posts

I am quite new to this thing..if u can explain me in detail? with first option u suggest?
Nagendra Kumar Busam
RE: how to preview jasper report withough saving the html or pdf file ?
December 24, 2012 10:00 PM
Answer

Nagendra Kumar Busam

Rank: Liferay Master

Posts: 637

Join Date: July 7, 2009

Recent Posts

asper Viewer.viewReport () has many overloaded methods, depending upon the method you want to use - set the relevant arguments needed for this method @ server side as attibutes using request.setAttribute()