Im new with Jasper and I'm struggling with simple grouping.
My dto which is passed:
@Getter
public class OrderPrintPreviewInputData {
private final List<OrderedTestInputData> tests;
....
}
OrderedTestInputData.class:
@Getter
public class OrderedTestInputData {
private final Long id;
@Setter
private String testType;
@Setter
private String materialType;
}
now my jrxml:
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="pzt-order-print-preview" language="groovy" pageWidth="595" pageHeight="842" columnWidth="556" leftMargin="20" rightMargin="19" topMargin="20" bottomMargin="20" uuid="406fbc92-1eae-45c7-93f1-f65ed1808b63">
<property name="ireport.zoom" value="1.610510000000001"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="626"/>
...
<subDataset name="orderedTests" uuid="448c9b60-118e-407a-b2c6-61db0f377e4e">
<field name="tests.testType" class="java.lang.String"/>
<field name="tests.materialType" class="java.lang.String"/>
</subDataset>
<parameter name="SUBREPORT_JASPER_FILE" class="java.lang.Object"/>
<field name="tests" class="java.util.List"/>
...
<detail>
<frame>
<reportElement positionType="Float" x="0" y="525" width="556" height="26" uuid="393eb4ce-1fa9-4e44-a560-a94ab2e2a04f">
<property name="com.jaspersoft.studio.element.name" value="ExaminationFrame"/>
<property name="com.jaspersoft.studio.unit.y" value="px"/>
</reportElement>
<subreport>
<reportElement positionType="Float" x="-3" y="16" width="556" height="10" uuid="8666b227-be06-4552-8a0d-12015455ea4a">
<property name="com.jaspersoft.studio.unit.y" value="px"/>
</reportElement>
<dataSourceExpression>
<![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{tests})]]>
</dataSourceExpression>
<subreportExpression>
<![CDATA[$P{SUBREPORT_JASPER_FILE}]]>
</subreportExpression>
</subreport>
</frame>
</detail>
The data is displayed that way:
row 1 - testType_1 | materialType_1
row 2 - testType_1 | materialType_2
row 3 - testType_2 | materialType_3
row 4 - testType_3 | materialType_4
row 5 - testType_3 | materialType_5
but now I need to display the results grouped by testType like below:
row 1 - testType_1 | materialType_1 + '\n' + materialType_2
row 2 - testType_2 | materialType_3
row 3 - testType_3 | materialType_4 + '\n' + materialType_5
I tried with such code but without any results:
<variable name="MaterialTypesAggregated" class="java.lang.String" resetType="Group" resetGroup="TestTypeGroup" calculation="System">
<variableExpression><![CDATA[(($V{MaterialTypesAggregated} != null ? $V{MaterialTypesAggregated} + ", " : "") + $F{tests.materialType})]]></variableExpression>
<initialValueExpression><![CDATA[""]]></initialValueExpression>
</variable>
<group name="TestTypeGroup">
<groupExpression><![CDATA[$F{tests.testType}]]></groupExpression>
<groupHeader>
<band height="20">
<textField>
<reportElement x="0" y="0" width="200" height="20" uuid="c4efc3da-c43d-4100-ad8d-0a0d358bf386"/>
<textFieldExpression><![CDATA[$F{tests.testType}]]></textFieldExpression>
</textField>
</band>
</groupHeader>
<groupFooter>
<band height="20">
<textField>
<reportElement x="0" y="0" width="400" height="20" uuid="b121bb43-86a9-4b7d-8e03-c81ccd938466"/>
<textFieldExpression><![CDATA["Material Types: " + $V{MaterialTypesAggregated}]]></textFieldExpression>
</textField>
</band>
</groupFooter>
</group>
with this code above I'm getting the errors:
Caused by: net.sf.jasperreports.engine.design.JRValidationException: Report design not valid :
1. Field not found : tests.materialType
2. Field not found : tests.testType
3. Field not found : tests.testType
4. Field not found : tests.testType
5. Field not found : tests.materialType