1
votes

I have developed a JasperReports report using csv datasource and successfully published on JasperReports Server.

Question : Now, I want switch the csv datasources based on the parameter (abc).

  • When parameter value "csv1" is selected by the user ----> sample.jrxml should connect to "path of csv1"
  • When parameter value "csv2" is selected by the user ----> sample.jrxml should connect to "path of csv2"

Note : I am not using tables in sample.jrxml file

Can anyone tell me how to achieve this?

1

1 Answers

1
votes

If you are using a CSV file as the source for your data, you could do something like this in your JRXML:

<parameter name="switchParam" class="java.lang.String" isForPrompting="false">
    <defaultValueExpression><![CDATA["abc"]]></defaultValueExpression>
</parameter>
<parameter name="net.sf.jasperreports.csv.source" class="java.lang.String" isForPrompting="false">
    <defaultValueExpression><![CDATA[$P{switchParam} == "abc" ? "path/to/CsvDataSource1" : "path/to/CsvDataSource2"]]></defaultValueExpression>
</parameter>

The CSV source can be passed in either as a property or a parameter, in your case the parameter offering more flexibility.