zaleskid1 Posted November 29, 2018 Share Posted November 29, 2018 Like you can notice on my test data (example below):report can have a lof ot topicstopic can have a lof of commentscomment can have a lot of authors Those are my POJOs: public class Report { private DateRange dateRange; private double sumOfcustomerWorkedHour; private List<CustomerReport> customerReports; } public class CustomerReport { private String name; private double workedHour; private List<ProjectReport> projectReports; } public class ProjectReport { private String name; private double workedHour; private List<UserReport> userReports; } public class UserReport { private String name; private double workedHour; }This is example test data (in json for better readability).{ "dateRange":{ "begin":"2016-09-01", "end":"2016-09-01" }, "sumOfcustomerWorkedHour":0.45, "customerReports":[ { "name":"Test customer", "workedHour":0.45, "projectReports":[ { "name":"Test project", "workedHour":0.25, "userReports":[ { "name":"Tom Smith", "workedHour":0.12 }, { "name":"John Kowalsky", "workedHour":0.13 } ] }, { "name":"Test project3", "workedHour":0.2, "userReports":[ { "name":"Jan Kowalski", "workedHour":0.08 }, { "name":"Thomas Adams", "workedHour":0.1 }, { "name":"John Snow", "workedHour":0.02 } ] } ] } ]Right now I create JasperPrint object by: public JasperPrint createJasperPrintObject(Report report) throws JRException { Map<String, Object> params = new HashMap<>(); params.put("SUBREPORT_DIR", tempPath()); params.put("begin", report.getDateRange().getBegin().toString()); params.put("end", report.getDateRange().getEnd().toString()); params.put("sumOfcustomerWorkedHour", report.getSumOfcustomerWorkedHour()); JRBeanCollectionDataSource customerReports = new JRBeanCollectionDataSource(report.getCustomerReports()); return JasperFillManager.fillReport(loadCompiledJasperReport(), params, customerReports); } And it works well, but is there a way that I would've make solution as below? To just transfer model as param and do all logic on jasper side?That way I would've be able to transfer LocalDate to Report and report would've choose public JasperPrint createJasperPrintObject(Report report) throws JRException { Map<String, Object> params = new HashMap<>(); params.put("SUBREPORT_DIR", tempPath()); params.put("MODEL", report); return JasperFillManager.fillReport(loadCompiledJasperReport(), params); }If yes than how should've I rewrite my jasper files?Main view (summary.jrxml): <?xml version="1.0" encoding="UTF-8"?> <!-- Created with Jaspersoft Studio version 7.2.0.final using JasperReports Library version 6.6.0 --> <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="summary" pageWidth="595" pageHeight="842" columnWidth="595" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" isFloatColumnFooter="true" uuid="f07170b9-79f1-43d9-8a98-54a5a3b1cc37"> <property name="com.jaspersoft.studio.data.defaultdataadapter" value="DataAdapter1.xml"/> <property name="com.jaspersoft.studio.unit." value="pixel"/> <property name="com.jaspersoft.studio.unit.pageHeight" value="pixel"/> <property name="com.jaspersoft.studio.unit.pageWidth" value="pixel"/> <property name="com.jaspersoft.studio.unit.topMargin" value="pixel"/> <property name="com.jaspersoft.studio.unit.bottomMargin" value="pixel"/> <property name="com.jaspersoft.studio.unit.leftMargin" value="pixel"/> <property name="com.jaspersoft.studio.unit.rightMargin" value="pixel"/> <property name="com.jaspersoft.studio.unit.columnWidth" value="pixel"/> <property name="com.jaspersoft.studio.unit.columnSpacing" value="pixel"/> <parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false"/> <parameter name="begin" class="java.lang.String" isForPrompting="false"/> <parameter name="end" class="java.lang.String" isForPrompting="false"/> <parameter name="sumOfcustomerWorkedHour" class="java.lang.Double" isForPrompting="false"> <defaultValueExpression><![CDATA[$P{sumOfcustomerWorkedHour}]]></defaultValueExpression> </parameter> <parameter name="customerReports" class="java.lang.String"/> <parameter name="subReportProject" class="net.sf.jasperreports.engine.JasperReport"/> <parameter name="subReportUser" class="net.sf.jasperreports.engine.JasperReport"/> <queryString language="JSON"> <![CDATA[]]> </queryString> <field name="name" class="java.lang.String"> <property name="net.sf.jasperreports.json.field.expression" value="name"/> <fieldDescription><![CDATA[name]]></fieldDescription> </field> <field name="projectReports" class="java.util.List"> <property name="net.sf.jasperreports.json.field.expression" value="projectReports"/> </field> <field name="workedHour" class="java.lang.Double"> <property name="net.sf.jasperreports.json.field.expression" value="workedHour"/> <fieldDescription><![CDATA[workedHour]]></fieldDescription> </field> <title> <band height="59" splitType="Stretch"> <textField> <reportElement x="60" y="40" width="160" height="19" uuid="47de6c0b-b9b5-4d0c-8b57-50edbc8501c2"/> <textElement textAlignment="Left" verticalAlignment="Middle"/> <textFieldExpression><![CDATA[$P{sumOfcustomerWorkedHour}]]></textFieldExpression> </textField> <staticText> <reportElement x="0" y="40" width="60" height="19" uuid="ccaf3795-0c75-4e55-a542-cb11aa504d6d"/> <textElement textAlignment="Left" verticalAlignment="Middle"> <font fontName="Times New Roman" size="12" isBold="true"/> </textElement> <text><![CDATA[suma:]]></text> </staticText> <textField> <reportElement x="60" y="20" width="120" height="20" uuid="12aa02c6-6242-428d-b0b6-78fda183b7e6"/> <textElement verticalAlignment="Middle"/> <textFieldExpression><![CDATA[$P{end}]]></textFieldExpression> </textField> <textField> <reportElement x="60" y="0" width="120" height="20" uuid="c26ee0c8-8ddc-4820-83c5-6d1bfd28a9e3"/> <textElement verticalAlignment="Middle"/> <textFieldExpression><![CDATA[$P{begin}]]></textFieldExpression> </textField> <staticText> <reportElement x="0" y="20" width="60" height="20" uuid="5950cd9a-283c-43cb-8d0f-1f5045d117cd"/> <textElement verticalAlignment="Middle"> <font fontName="Times New Roman" size="12" isBold="true"/> </textElement> <text><![CDATA[DO:]]></text> </staticText> <staticText> <reportElement x="0" y="0" width="60" height="20" uuid="08bd9eb6-5cf9-4479-80c8-e1190ffb6714"/> <textElement verticalAlignment="Middle"> <font fontName="Times New Roman" size="12" isBold="true"/> </textElement> <text><![CDATA[OD:]]></text> </staticText> </band> </title> <columnHeader> <band height="30" splitType="Stretch"> <staticText> <reportElement x="100" y="0" width="200" height="30" uuid="004632dc-0492-4dcb-9321-f09d707a09a6"/> <box> <topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/> <leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/> <bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/> <rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/> </box> <textElement textAlignment="Center" verticalAlignment="Middle"> <font fontName="Times New Roman" size="15" isBold="true"/> </textElement> <text><![CDATA[klient / projekt / pracownik]]></text> </staticText> <staticText> <reportElement x="300" y="0" width="200" height="30" uuid="a48c7e2c-2013-474f-910a-2a4fb4919383"/> <box> <topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/> <leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/> <bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/> <rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/> </box> <textElement textAlignment="Center" verticalAlignment="Middle"> <font fontName="Times New Roman" size="15" isBold="true"/> </textElement> <text><![CDATA[czas pracy]]></text> </staticText> </band> </columnHeader> <detail> <band height="70" splitType="Stretch"> <textField> <reportElement x="100" y="0" width="200" height="30" uuid="03f6a7dc-efa8-4b0b-ba87-1fcfb10ba598"> <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="667fa1ca-acfd-4a4b-bdee-fb462d853ce4"/> <property name="com.jaspersoft.studio.unit.leftIndent" value="px"/> </reportElement> <box> <topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/> <leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/> <bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/> <rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/> </box> <textElement verticalAlignment="Middle"> <paragraph leftIndent="1"/> </textElement> <textFieldExpression><![CDATA[$F{name}]]></textFieldExpression> </textField> <textField> <reportElement x="300" y="0" width="200" height="30" uuid="43bc40e6-e591-4063-bf0b-8852d4ea87c4"/> <box> <topPen lineWidth="1.0"/> <leftPen lineWidth="1.0"/> <bottomPen lineWidth="1.0"/> <rightPen lineWidth="1.0"/> </box> <textElement textAlignment="Right" verticalAlignment="Middle"/> <textFieldExpression><![CDATA[$F{workedHour}]]></textFieldExpression> </textField> <subreport> <reportElement x="0" y="30" width="595" height="40" uuid="0b838e70-d16a-4c9a-b6cb-c9b4ab3afbfa"> <property name="com.jaspersoft.studio.unit.height" value="px"/> </reportElement> <parametersMapExpression><![CDATA[$P{REPORT_PARAMETERS_MAP}]]></parametersMapExpression> <dataSourceExpression> <![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{projectReports})]]></dataSourceExpression> <subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "/project.jasper"]]></subreportExpression> </subreport> </band> </detail> </jasperReport> First subreport (project.jrxml): <?xml version="1.0" encoding="UTF-8"?> <!-- Created with Jaspersoft Studio version 7.2.0.final using JasperReports Library version 6.6.0 --> <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="project" pageWidth="595" pageHeight="842" columnWidth="595" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" isFloatColumnFooter="true" uuid="55e0a9d7-656e-4b3e-98b7-da762f908266"> <property name="com.jaspersoft.studio.data.defaultdataadapter" value="nowszy json.xml"/> <property name="com.jaspersoft.studio.unit." value="pixel"/> <property name="com.jaspersoft.studio.unit.pageHeight" value="pixel"/> <property name="com.jaspersoft.studio.unit.pageWidth" value="pixel"/> <property name="com.jaspersoft.studio.unit.topMargin" value="pixel"/> <property name="com.jaspersoft.studio.unit.bottomMargin" value="pixel"/> <property name="com.jaspersoft.studio.unit.leftMargin" value="pixel"/> <property name="com.jaspersoft.studio.unit.rightMargin" value="pixel"/> <property name="com.jaspersoft.studio.unit.columnWidth" value="pixel"/> <property name="com.jaspersoft.studio.unit.columnSpacing" value="pixel"/> <parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false"/> <queryString language="JSON"> <![CDATA[customerReports.projectReports]]> </queryString> <field name="name" class="java.lang.String"> <property name="net.sf.jasperreports.json.field.expression" value="name"/> <fieldDescription><![CDATA[name]]></fieldDescription> </field> <field name="workedHour" class="java.lang.Double"> <property name="net.sf.jasperreports.json.field.expression" value="workedHour"/> <fieldDescription><![CDATA[workedHour]]></fieldDescription> </field> <field name="userReports" class="java.util.List"> <property name="net.sf.jasperreports.json.field.expression" value="userReports"/> <fieldDescription><![CDATA[userReports]]></fieldDescription> </field> <detail> <band height="50" splitType="Stretch"> <textField> <reportElement x="100" y="0" width="200" height="30" uuid="9d0dd2a5-526f-4184-b6f2-54f69c2915d6"> <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="d7b95de3-c8af-4278-9735-3f0a01bde44f"/> </reportElement> <box> <topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/> <leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/> <bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/> <rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/> </box> <textElement verticalAlignment="Middle"> <paragraph leftIndent="6"/> </textElement> <textFieldExpression><![CDATA[$F{name}]]></textFieldExpression> </textField> <textField> <reportElement x="300" y="0" width="200" height="30" uuid="3f2d7322-1f8f-4d40-ba5c-0290fcc3cfae"/> <box> <topPen lineWidth="1.0"/> <leftPen lineWidth="1.0"/> <bottomPen lineWidth="1.0"/> <rightPen lineWidth="1.0"/> </box> <textElement textAlignment="Right" verticalAlignment="Middle"> <paragraph rightIndent="1"/> </textElement> <textFieldExpression><![CDATA[$F{workedHour}]]></textFieldExpression> </textField> <subreport> <reportElement x="0" y="30" width="595" height="20" uuid="4dd99e2f-e47e-4579-8f97-b3ddbd15cbb2"/> <parametersMapExpression><![CDATA[$P{REPORT_PARAMETERS_MAP}]]></parametersMapExpression> <dataSourceExpression> <![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{userReports})]]></dataSourceExpression> <subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "/user.jasper"]]></subreportExpression> </subreport> </band> </detail> </jasperReport>Second subreport (user.jrxml): <?xml version="1.0" encoding="UTF-8"?> <!-- Created with Jaspersoft Studio version 7.2.0.final using JasperReports Library version 6.6.0 --> <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="user" pageWidth="595" pageHeight="842" columnWidth="595" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" isFloatColumnFooter="true" uuid="a89f1b2e-859f-4ffc-86a7-c5a15fef4f2b"> <property name="com.jaspersoft.studio.data.defaultdataadapter" value="nowszy json.xml"/> <property name="com.jaspersoft.studio.unit." value="pixel"/> <property name="com.jaspersoft.studio.unit.pageHeight" value="pixel"/> <property name="com.jaspersoft.studio.unit.pageWidth" value="pixel"/> <property name="com.jaspersoft.studio.unit.topMargin" value="pixel"/> <property name="com.jaspersoft.studio.unit.bottomMargin" value="pixel"/> <property name="com.jaspersoft.studio.unit.leftMargin" value="pixel"/> <property name="com.jaspersoft.studio.unit.rightMargin" value="pixel"/> <property name="com.jaspersoft.studio.unit.columnWidth" value="pixel"/> <property name="com.jaspersoft.studio.unit.columnSpacing" value="pixel"/> <queryString language="JSON"> <![CDATA[customerReports.projectReports.userReports]]> </queryString> <field name="name" class="java.lang.String"> <property name="net.sf.jasperreports.json.field.expression" value="name"/> <fieldDescription><![CDATA[name]]></fieldDescription> </field> <field name="workedHour" class="java.lang.Double"> <property name="net.sf.jasperreports.json.field.expression" value="workedHour"/> <fieldDescription><![CDATA[workedHour]]></fieldDescription> </field> <background> <band splitType="Stretch"/> </background> <detail> <band height="30" splitType="Stretch"> <textField> <reportElement x="100" y="0" width="200" height="30" uuid="c9e90893-ac2d-43ee-9d40-04f6f74a2088"> <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="4f1d70b5-0282-43db-9e40-5cf0b4adaf20"/> <property name="com.jaspersoft.studio.unit.leftIndent" value="px"/> </reportElement> <box> <topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/> <leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/> <bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/> <rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/> </box> <textElement verticalAlignment="Middle"> <paragraph lineSpacing="Single" lineSpacingSize="1.0" leftIndent="11"/> </textElement> <textFieldExpression><![CDATA[$F{name}]]></textFieldExpression> </textField> <textField> <reportElement x="300" y="0" width="200" height="30" uuid="f78c1b1d-9627-449f-a957-ca961e48cabf"> <property name="com.jaspersoft.studio.spreadsheet.connectionID" value="0f1b47b1-770b-481f-a8de-49241233f4fe"/> <property name="com.jaspersoft.studio.unit.rightIndent" value="px"/> </reportElement> <box> <topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/> <leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/> <bottomPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/> <rightPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/> </box> <textElement textAlignment="Right" verticalAlignment="Middle"> <paragraph rightIndent="1"/> </textElement> <textFieldExpression><![CDATA[$F{workedHour}]]></textFieldExpression> </textField> </band> </detail> </jasperReport> <?xml version="1.0" encoding="UTF-8"?> ,>,> Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now