on 12-11-2017 5:13 AM
The project use Java sping mvc, have bean call ‘report.rpt' file.
Whatever,same follow codeing , export PDF file not newest data.
I think, maybe rpt not refresh data from database.
And try refresh data by :reportClientDoc.getReportSource().refresh(); , but can not export file to web.
Up description,i need more help , thanks.
Java bean:
/**
*
*/
package com.te.spring.controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
import com.crystaldecisions.report.web.viewer.ReportExportControl;
import com.crystaldecisions.reports.sdk.ParameterFieldController;
import com.crystaldecisions.reports.sdk.ReportClientDocument;
import com.crystaldecisions.sdk.occa.report.data.Fields;
import com.crystaldecisions.sdk.occa.report.exportoptions.ExportOptions;
import com.crystaldecisions.sdk.occa.report.exportoptions.ReportExportFormat;
import com.te.bean.empschedule.THrmScheduleDept;
/**
* @author chen-yu
* @email mimi2008yu@163.com
*/
public class Schedulecurrentreportoutfile implements Controller {
private SessionFactory sessionFactory;
private Session session;
private Transaction transaction;
public SessionFactory getSessionFactory() {
return sessionFactory;
}
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}
/* (non-Javadoc)
* @see org.springframework.web.servlet.mvc.annotation.ModelAndViewResolver#resolveModelAndView(java.lang.reflect.Method, java.lang.Class, java.lang.Object, org.springframework.ui.ExtendedModelMap, org.springframework.web.context.request.NativeWebRequest)
*/
public ModelAndView handleRequest(HttpServletRequest arg0,
HttpServletResponse arg1) throws Exception {
// TODO Auto-generated method stub
if (!(arg0.getParameter("deptoption")=="") && !(arg0.getParameter("deptoption")==null)) {
ReportClientDocument reportClientDoc = new ReportClientDocument();
//ReportDocument reportClientDoc = new ReportDocument();
reportClientDoc.open("VIEW/RPT/Schedulereportcurrent.rpt", 0);
reportClientDoc.getReportSource().dispose();
System.out.println("Refresh...");
//reportClientDoc.getReportSource().refresh();
System.out.println("Refreshed");
String SelectionFormula = "";
if (!(arg0.getParameter("deptoption")=="") && !(arg0.getParameter("deptoption")==null)) {
SelectionFormula = "{t_hrm_schedule_current.SCHEDULE_PARENT_DEPT}='" + arg0.getParameter("deptoption") +"'";
//System.out.println(SelectionFormula);
}
if (!(arg0.getParameter("groupsselect")=="") && !(arg0.getParameter("groupsselect")==null)) {
SelectionFormula = SelectionFormula + " and {t_hrm_schedule_current.SCHEDULE_GROUP_ID}='" + arg0.getParameter("groupsselect") +"'";
//System.out.println(SelectionFormula);
}
if (!(arg0.getParameter("empsselect")=="") && !(arg0.getParameter("empsselect")==null)) {
SelectionFormula = SelectionFormula + " and {t_hrm_schedule_current.EMP_ID}='" + arg0.getParameter("empsselect") +"'";
//System.out.println(SelectionFormula);
}
if (SelectionFormula != "") {
reportClientDoc.setRecordSelectionFormula(SelectionFormula);
}
//UI Parameter: Department
session = getSessionFactory().openSession();
THrmScheduleDept dept = (THrmScheduleDept)session.createQuery("From THrmScheduleDept Where parentDeptId='" + Integer.parseInt(arg0.getParameter("deptoption")) + "'").uniqueResult();
Fields fields = reportClientDoc.getDataDefController().getDataDefinition().getParameterFields();
ParameterFieldController parameterFieldController = reportClientDoc.getDataDefController().getParameterFieldController();
parameterFieldController.setCurrentValue("", "Department", dept.getParentDeptName());
//reportClientDoc.getReportSource().refresh();
//Export File RTF
ReportExportControl exportControl=new ReportExportControl();
ExportOptions exportOptions=new ExportOptions();
exportOptions.setExportFormatType(ReportExportFormat.PDF);
exportControl.setReportSource(reportClientDoc.getReportSource());
exportControl.setExportOptions(exportOptions);
exportControl.setExportAsAttachment(true);
exportControl.setName("NextMonthScheduleReport");
System.out.println("2");
exportControl.processHttpRequest(arg0, arg1, arg0.getServletContext(), null);
exportControl.dispose();
reportClientDoc.close();
System.out.println("1");
}
return null;
}
}
Add two line code, can resolve data refresh.
reportClientDoc.open("VIEW/RPT/Schedulereportcurrent.rpt",OpenReportOptions._openAsReadOnly);
reportClientDoc.getDatabaseController().logon("user", "password");
reportClientDoc.getReportSource().refresh();
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
91 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.