|
public abstract class ReportBaseAction extends ActionSupport {
private static final long serialVersionUID = 190881665780129568L;
protected List rptData;
private String rtpFmt;
protected String rptName;
protected String rptFileName;
private ReportService reportService;
protected abstract void getReportResult();
public String goRPT() throws Exception {
compileRpt(JasperReportConstants.FORMAT_HTML);
return rtpFmt;
}
public String goPrint() throws Exception {
String pathPrefix = ServletActionContext.getServletContext()
.getRealPath("/jasper/");
JasperPrint jasperPrint = null;
JasperReport jasperReport = null;
compileRpt(ReportService.FORMAT_PRINT);
//datasource
JRDataSource dataSource = new JRBeanCollectionDataSource(this.getRptData()) ;
//load report template
jasperReport = (JasperReport)JRLoader.loadObject(pathPrefix+"/"+this.getRptFileName()) ;
Map<String,String> param = new HashMap<String,String>();
//load report data
jasperPrint = JasperFillManager.fillReport(jasperReport, param, dataSource) ;
JasperPrintManager.printReport(jasperPrint, true) ;
return "success";
}
private void compileRpt(String targetType) throws Exception {
getReportResult();
String pathPrefix = ServletActionContext.getServletContext()
.getRealPath("/jasper/");
this.setRptFileName(reportService.compileJasper(pathPrefix, this.getRptName(),targetType));
//String reportSource;
//reportSource = ServletActionContext.getServletContext().getRealPath(
//"/jasper/" + rptName + ".jrxml");
//File parent = new File(reportSource).getParentFile();ֻ�Ǻ���ͬ����
//JasperCompileManager.compileReportToFile(reportSource, new File(parent,
//rptName + ".jasper").getAbsolutePath());
}
public String getRtpFmt() {
return rtpFmt;
}
public void setRtpFmt(String rtpFmt) {
this.rtpFmt = rtpFmt;
}
public String getRptName() {
return rptName;
}
public void setRptName(String rptName) {
this.rptName = rptName;
}
public ReportService getReportService() {
return reportService;
}
public void setReportService(ReportService reportService) {
this.reportService = reportService;
}
public List getRptData() {
return rptData;
}
public void setRptData(List rptData) {
this.rptData = rptData;
}
public String getRptFileName() {
return rptFileName;
}
public void setRptFileName(String rptFileName) {
this.rptFileName = rptFileName;
}
} |
|