以下は、portletAction の serveResource メソッドで呼び出している関数です。
public String ajax_GenerateReportsforCampaignAdvertiseDateRangeWithCustomQuery(
ResourceRequest request, ResourceResponse response,
String str_camp_id) throws Exception {
PortletContext pc = request.getPortletSession().getPortletContext();
String Pathjrxml = pc
.getRealPath("/src_reports/Campaign_Advertise_DateRange_Report.jrxml");
String pathjasper = pc
.getRealPath("/src_reports/Campaign_Advertise_DateRange_Report.jasper");
_report_path = pc.getRealPath("htmlreport/report");
_report_name = Calendar.getInstance().getTimeInMillis() + "";
_report_path = _report_path + _report_name;
String str_start_date = request.getParameter("f_start_date");
String str_end_date = request.getParameter("f_end_date");
Date filter_start_date = null;
Date filter_end_date = null;
List<CampaignReport> temp_campReportList = new ArrayList<CampaignReport>(
8);
log.info("ajax_Generate Reports For Campaign Advertise With Date Range Enter");
/** Dateformat which will convert filter date string in to specified **/
DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
filter_start_date = dateFormat.parse(str_start_date);
filter_end_date = dateFormat.parse(str_end_date);
str_end_date = dateFormat.format(filter_end_date);
log.info("Filter Start Date : " + filter_start_date);
log.info("Filter End Date : " + filter_end_date);
ReportCustomQuery cust = new ReportCustomQuery();
String pathImage = request.getContextPath()
+ "/eMenuAdvertise-portlet/img/eMenu Logo_1.png";
temp_campReportList = cust.GetAdvertiseListByCampaignsForReports(
Long.parseLong(str_camp_id), filter_start_date,
filter_end_date, pathImage);
System.setProperty("java.awt.headless", "true");
JRBeanCollectionDataSource beanCollectionDataSource = new JRBeanCollectionDataSource(
temp_campReportList);
System.out.println(" bean collection "
+ beanCollectionDataSource.getRecordCount());
System.out.println("Compile Start");
JasperCompileManager.compileReportToFile(Pathjrxml, pathjasper);
JasperPrint jasperPrint = JasperFillManager.fillReport(pathjasper,
new HashMap<String, Object>(), beanCollectionDataSource);
log.info("Compile End");
log.info(" report path " + _report_path);
JasperExportManager.exportReportToHtmlFile(jasperPrint, _report_path
+ ".html");
JasperExportManager.exportReportToPdfFile(jasperPrint, _report_path
+ ".pdf");
log.info("ajax_GenerateReports Leave");
return _report_name;
}
このメソッドを呼び出す ajax 呼び出しは次のとおりです。
<script type="text/javascript">
function GenerateReport(addToDo) {
var camp_ID = document.getElementById('camp_id').value;
var f_start_date = document
.getElementById('Start_validBeforeDatepicker').value;
var f_end_date = document.getElementById('End_validAfterDatepicker').value;
$.ajax({
url : addToDo,
data : {
"camp_id" : camp_ID,
"f_start_date" : f_start_date,
"f_end_date" : f_end_date,
"CMD" : camp_ID
},
type : "GET",
timeout : 20000,
dataType : "text",
async : false,
success : function(data) {
createRenderURL(data);
}
});
以下は、新しく作成されたhtmlファイルの動的なresourceurlを作成している私のcreatRenderUrl javascriptであり、そのhtmlページをiframeにプレビューとして表示しています
function createRenderURL(str_path,contextpath,resourceurl) {
AUI().use('liferay-portlet-url', function(A) {
var renderURL = Liferay.PortletURL.createRenderURL();
renderURL.setParameter("jspPage", "/htmlreport/report" + str_path);
renderURL.setPortletId("eMenuAdvertise_WAR_eMenuAdvertiseportlet");
var p= "<%=renderRequest.getContextPath()%>";
var downloadurl="/eMenuAdvertise-portlet/htmlreport/report"+ str_path+".pdf";
var x=document.getElementById("outPopUp");
x.style.visibility="hidden";
document.getElementById('reportpreview').src = "/eMenuAdvertise-portlet/htmlreport/report"+ str_path+".html";
$("#download").click(function () {
DownloadFile(downloadurl,resourceurl);
});
return downloadurl;
});
}
しかし、私がやりたいことは、ファイルを保存せずにレポートをプレビューすることですか? 急いで?