Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ReportExportControl not setting parameter fields

Status
Not open for further replies.

krysna

Programmer
May 20, 2008
22
I am trying to pass parameters to a report and export it to PDF. I am setting the parameters in the Fields object and then calling reportExportControl.setParameterFields(fields). The size of fields is 2. However, after setting, the size of reportExportControl.getParameterFields() is 0. The even more interesting problem is that originally, I was actually getting 1 parameter (but not the other), and after I started putting in debug statements to figure out what was going on, it eventually stopped getting any params at all. This appears to be a bug in crystal's code, but if any of you have any ideas of something I could be doing wrong, I'm all ears. The report renders just fine when I use CrystalReportViewer, but if I try to do the export, it doesn't. This was also working the last time I touched the code (about a month ago). Also, other reports with params are working just fine. Is this another instance of Crystal just being flaky for us java users, or is it something I can actually fix? Very grateful for any ideas you may have.

Here is my code:
Code:
try {
	String reportName = (String) request.getParameter("report");
	String report = "/tiles/reports/" + reportName + ".rpt";

	ReportClientDocument reportClientDoc = new ReportClientDocument();			
	reportClientDoc.open(report, OpenReportOptions._openAsReadOnly);

	ConfigFileConnectionFactory cf = new ConfigFileConnectionFactory();
	String userName=cf.getUsername();
	String password=cf.getPassword();
	String driverName = cf.getDriver();
	String jndiName = "jdbc/IFSpi";
	String connectString = cf.getUrl();
	JRCHelperSample.changeDataSource(reportClientDoc, userName, password, connectString, driverName, jndiName);
	Fields fields = (Fields)request.getAttribute("parameterList");
	System.out.println("passed in param fields");
	//all of my params print out below with no problems
	for (int i = 0; i < fields.size(); i++) {
		ParameterField pf = (ParameterField)fields.get(i);
		Values v = pf.getCurrentValues();
		if (v.size() > 0) {
			ParameterFieldDiscreteValue pfdv = (ParameterFieldDiscreteValue)v.get(0);
			System.out.println(pf.getName() + " - " + pfdv.getValue());
		} else {
			System.out.println(pf.getName());
		}
	}
	IReportSource reportSource = reportClientDoc.getReportSource();				
	ReportExportControl exportControl = new ReportExportControl();
	ExportOptions exportOptions = new ExportOptions();
	exportOptions.setExportFormatType(ReportExportFormat.PDF);
	exportControl.setReportSource(reportSource);
	exportControl.setExportOptions(exportOptions);

	exportControl.setExportAsAttachment(false);
	exportControl.setEnableParameterPrompt(false);
	exportControl.setParameterFields(fields);

	System.out.println("line 122 " + exportControl.getParameterFields()); //this prints "[]"
	System.out.println("line 123 " + exportControl.getParameterFields().size()); //this prints "0"
	System.out.println("line 124 " + fields.size()); //this prints "2"
	System.out.println("exportcontrol param fields");
	//all the params in the list should print below.  I was getting one of my params (should be two), but now I get none.  I had not changed the code other than re-ordering and adding debug lines.
	for (int i = 0; i < exportControl.getParameterFields().size(); i++) {
		ParameterField pf = (ParameterField)exportControl.getParameterFields().get(i);
		Values v = pf.getCurrentValues();
		if (v.size() > 0) {
			ParameterFieldDiscreteValue pfdv = (ParameterFieldDiscreteValue)v.get(0);
			System.out.println(pf.getName() + " - " + pfdv.getValue());
		} else {
			System.out.println(pf.getName());
		}
	}
	exportControl.refresh();
	exportControl.processHttpRequest(request, response, getServletConfig().getServletContext(), null);
	exportControl.dispose();
			
} catch (ReportSDKExceptionBase e) {
	LOG.debug(e);
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top