I'm working on a webportal project that will allow people to view and export reports and I would really like to make use of csv metadata export option. My problem is that although I can export the metadata from jasper studio I can't seem to get it set up on the server. I've already seen this link http://jasperreports.sourceforge.net/sample.reference/jasper/#csvmetadat... of how to configure the reports and a simple java example but that doesn't get me very far into configuring the server to use the metadata exporter instead of the regular csv exporter. I'm using jasperreports server 6.0.1 and I've built it from source locally so if I need to do any server configuration I can. Any help would be great.
1 Answer:
I love it when I get to answer my own questions haha.
Anyways, I figured out how to configure the server to use the JRCsvMetadataExporter. I basically followed the directions here, and edited the viewReportBeans.xml, using the csvexport configuration as an example but renaming things to csvmetadataexporter. Then I created a ReportCsvMetadataExporter using the ReportCsvExporter as a template, but where it used JRCsvExporter and JRCsvExporterParameter, I used the JRCsvMetadataExporter and JRCsvMetadataExporterParameter (these are the classes jasper wrote for us). And then I rebuilt the server and was able to export it fine.
So my ReportCsvMetadataExporter export method looked like:
public void export(RequestContext context, ExecutionContext executionContext, String reportUnitURI, Map baseParameters) throws JRException { JRCsvMetadataExporter exporter = new JRCsvMetadataExporter(getJasperReportsContext()); exporter.setParameters(baseParameters); CsvExportParametersBean exportParams = (CsvExportParametersBean)getExportParameters(context); if (exportParams.isOverrideReportHints()) { exporter.setParameter(JRExporterParameter.PARAMETERS_OVERRIDE_REPORT_HINTS, Boolean.TRUE); } exporter.setParameter(JRCsvMetadataExporterParameter.FIELD_DELIMITER, exportParams.getFieldDelimiter()); exporter.exportReport(); }
my viewReportBeans.xml had:
<bean id="reportCsvMetadataExporter" class="com.jaspersoft.jasperserver.war.action.ReportCsvMetadataExporter" parent="baseReportExporter"> <property name="exportParameters" ref="csvExportParameters"/> <property name="setResponseContentLength" value="true"/> </bean> ... <bean id="csvMetadataExporterConfiguration" class="com.jaspersoft.jasperserver.war.action.ExporterConfigurationBean"> <property name="descriptionKey" value="jasper.report.view.hint.export.csv"/> <property name="iconSrc" value="/images/csv.gif"/> <property name="parameterDialogName" value="csvExportParams"/> <property name="exportParameters" ref="csvExportParameters"/> <property name="currentExporter" ref="reportCsvMetadataExporter"/> </bean> ... <entry key="csv" value-ref="csvMetadataExporterConfiguration"/>
This isn't perfect though as I only needed it to override the csv export and only in the web service and Jive UI. It doesn't cover scheduling or adhoc reports and doesn't necessarily play nice with those configurations either so YMMV, but hopefully this helps! and sorry it took me so long to update this
Hi,
I'm writing it as a comment to your post as I cannot comment your answer but I would be really interested to see the changes you made to the server.
I think we need to use the csvmetadata exporter too from the server and I'm not sure exactly of everything I need to change.
Hi srang, I am trying to accomplish the same task but am running into some issues. Could you post a link to code which you required changing?
Hmmm the code is in a private repo but I can try and post some relevant snippets