I am working on jrxml to create dynamic reports. I have parameterized the columns i.e. the jrxml for that report can be used to generate other reports as well.
However, I have not managed to make the fields flexible. That is, if the user selects 4 columns it would work but if 1 or 2 or 3 columns are selected, it gives an error since the field names are unidentified.
Please post a solution urgently if something like a default expression for fieldname can be created or a for loop/java script can be used.
Moreover, how can jasper designer be exactly used to achieve this?
The jrxml is as follows:
<?xml version="1.0"?>
<!DOCTYPE jasperReport
PUBLIC "-//JasperReports//DTD Report Design//EN"
"http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">
<jasperReport name="report1">
<parameter name="reportTitle" class="java.lang.String"/>
<parameter name="author" class="java.lang.String"/>
<parameter name="startDate" class="java.lang.String"/>
<parameter name="C1" class="java.lang.String">
<defaultValueExpression>
new java.lang.String("")
</defaultValueExpression>
</parameter>
<parameter name="C2" class="java.lang.String">
<defaultValueExpression>
new java.lang.String("")
</defaultValueExpression>
</parameter>
<parameter name="C3" class="java.lang.String">
<defaultValueExpression>
new java.lang.String("")
</defaultValueExpression>
</parameter>
<parameter name="C4" class="java.lang.String">
<defaultValueExpression>
new java.lang.String("default parameter value")
</defaultValueExpression>
</parameter>
<field name="COLUMN_1" class="java.lang.Integer"/>
<field name="COLUMN_2" class="java.lang.Integer"/>
<field name="COLUMN_3" class="java.lang.Integer"/>
<field name="COLUMN_4" class="java.lang.Integer"/>
<title>
<band height="60">
<textField>
<reportElement x="0" y="10" width="500" height="40"/>
<textElement textAlignment="Center">
<font size="24"/>
</textElement>
<textFieldExpression class="java.lang.String">
<![CDATA[$P{reportTitle}]]>
</textFieldExpression>
</textField>
<textField>
<reportElement x="0" y="40" width="500" height="20"/>
<textElement textAlignment="Center"/>
<textFieldExpression class="java.lang.String">
<![CDATA["Run by: " + $P{author}
+ " on " + $P{startDate}]]>
</textFieldExpression>
</textField>
</band>
</title>
<columnHeader>
<band height="30">
<rectangle>
<reportElement x="0" y="0" width="500" height="25"/>
<graphicElement/>
</rectangle>
<textField>
<reportElement x="0" y="5" width="170" height="15"/>
<textFieldExpression class="java.lang.String">
<![CDATA[$P{C1}]]>
</textFieldExpression>
</textField>
<textField>
<reportElement x="70" y="5" width="170" height="15"/>
<textFieldExpression class="java.lang.String">
<![CDATA[$P{C2}]]>
</textFieldExpression>
</textField>
<textField>
<reportElement x="150" y="5" width="150" height="15"/>
<textFieldExpression class="java.lang.String">
<![CDATA[$P{C3}]]>
</textFieldExpression>
</textField>
<textField>
<reportElement x="300" y="5" width="150" height="15"/>
<textFieldExpression class="java.lang.String">
<![CDATA[$P{C4}]]>
</textFieldExpression>
</textField>
</band>
</columnHeader>
<detail>
<band height="20">
<textField>
<reportElement x="5" y="0" width="50" height="15"/>
<textElement/>
<textFieldExpression class="java.lang.Integer">
<![CDATA[$F{COLUMN_1}]]>
</textFieldExpression>
</textField>
<textField>
<reportElement x="90" y="0" width="150" height="15"/>
<textElement/>
<textFieldExpression class="java.lang.Integer">
<![CDATA[$F{COLUMN_2}]]>
</textFieldExpression>
</textField>
<textField>
<reportElement x="170" y="0" width="50" height="15"/>
<textElement/>
<textFieldExpression class="java.lang.Integer">
<![CDATA[$F{COLUMN_3}]]>
</textFieldExpression>
</textField>
<textField>
<reportElement x="320" y="0" width="150" height="15"/>
<textElement/>
<textFieldExpression class="java.lang.Integer">
<![CDATA[$F{COLUMN_4}]]>
</textFieldExpression>
</textField>
</band>
</detail>
</jasperReport>