JasperReports: generation error from java with external fonts - jasper-reports

My program generates an error for arabic letter :
cannot assign instance of net.sf.jasperreports.engine.base.JRBaseStaticText to field
net.sf.jasperreports.engine.base.JRBaseParagraph.paragraphContainer of type
net.sf.jasperreports.engine.JRParagraphContainer in instance of
net.sf.jasperreports.engine.base.JRBaseParagraph
I am using:
iReport 4.0.2
Windows XP
jasperreports-fonts-4.0.2.jar
jasperreports 4.0.2.jar
jasperreports-extensions-3.5.3
My .jrxml file is:
<?xml version="1.0" encoding="UTF-8"?>
<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="report1" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<parameter name="strTitle" class="java.lang.String"/>
<field name="vchDhirams" class="java.lang.String"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="21" splitType="Stretch">
<staticText>
<reportElement x="221" y="1" width="100" height="20"/>
<textElement markup="none"/>
<text><![CDATA[$P{strTitle}]]></text>
</staticText>
</band>
</title>
<pageHeader>
<band height="35" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="37" splitType="Stretch">
<staticText>
<reportElement x="294" y="17" width="135" height="20"/>
<textElement>
<font pdfEncoding="Identity-H" isPdfEmbedded="true"/>
</textElement>
<text><![CDATA[ستلام قسيمة]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="125" splitType="Stretch"/>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>
Where is my fault? Please suggest me.
Thanks in advance.

Related

Jasper Sub Report Sizing Issue

Looking for the best way to solve my dilemma. I am building a report and the data source that is being used is JSON <- Not much experience with JSON.
This is how data looks coming across to me via JSON
Parent
Child
Child (NEED SOME FIELDS HERE FOR HEADER)
FINAL CHILD (Need Fields In Here) (Setup as array bc multiple of Final Child)
FINAL CHILD
FINAL CHILD and so on (FINAL CHILD will be repeating in the Detail section.)
ALSO FINAL CHILD IS SETUP IN ARRAY FOR EACH FINAL CHILD
Currently, I have built a master and subreport. I do not need to pass any data because of the parent only has children... but could not get it working where the detail section of the master report would cycle through all the Final Children.
Master Report PreView:
SubReport PreView:
No matter what I do to the sizing, I cannot get it to shrink down in size and compactness...
Master Report Code
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.4.0.final using JasperReports Library version 6.4.1 -->
<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="Test4BD" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="65794bef-41ec-4ebe-9237-6c5db5cb403c">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="BD JSON Data Adapter"/>
<queryString language="json">
<![CDATA[tXML.Message.InboundReportXML.MESSAGEDATA.ASNDATA.INBOUNDHEADER]]>
</queryString>
<field name="ASNID" class="java.lang.String">
<fieldDescription><![CDATA[ASNID]]></fieldDescription>
</field>
<field name="ASN" class="java.lang.String">
<fieldDescription><![CDATA[ASN]]></fieldDescription>
</field>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="7" splitType="Stretch"/>
</title>
<pageHeader>
<band height="14" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="62" splitType="Stretch">
<textField>
<reportElement x="70" y="0" width="100" height="30" uuid="0f247a53-6ea3-462d-a655-0e3f02f2b611"/>
<textFieldExpression><![CDATA[$F{ASNID}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="330" y="0" width="100" height="30" uuid="2c72da14-4800-4d2c-af67-58d27232133d"/>
<textFieldExpression><![CDATA[$F{ASN}]]></textFieldExpression>
</textField>
</band>
</columnHeader>
<detail>
<band height="75" splitType="Stretch">
<subreport>
<reportElement x="40" y="0" width="460" height="70" uuid="684434fc-a528-4e65-b7e8-6192048ae611"/>
<parametersMapExpression><![CDATA[$P{REPORT_PARAMETERS_MAP}]]></parametersMapExpression>
<subreportExpression><![CDATA["SubReport2.jasper"]]></subreportExpression>
</subreport>
</band>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>
SubReport:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.4.0.final using JasperReports Library version 6.4.1 -->
<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="SubReport2" pageWidth="595" pageHeight="842" whenNoDataType="AllSectionsNoDetail" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="2d15bbaf-6da1-4158-83b1-6a069fa6144b">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="BD JSON Data Adapter"/>
<queryString language="json">
<![CDATA[tXML.Message.InboundReportXML.MESSAGEDATA.ASNDATA.INBOUNDHEADER.INBOUNDDETAILS]]>
</queryString>
<field name="ASNDETAILID" class="java.lang.String">
<fieldDescription><![CDATA[ASNDETAILID]]></fieldDescription>
</field>
<field name="LINENBR" class="java.lang.String">
<fieldDescription><![CDATA[LINENBR]]></fieldDescription>
</field>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="8" splitType="Stretch"/>
</title>
<pageHeader>
<band height="9" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="32" splitType="Stretch">
<staticText>
<reportElement x="84" y="0" width="100" height="30" uuid="3b17e526-5b45-45db-b75f-4a86a1608bec"/>
<text><![CDATA[ASNDETAILID]]></text>
</staticText>
<staticText>
<reportElement x="310" y="0" width="100" height="30" uuid="cd6e9ad5-60a5-4041-894d-970faa1d4bd5"/>
<text><![CDATA[LINENBR]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="33" splitType="Stretch">
<textField>
<reportElement x="70" y="0" width="100" height="30" uuid="e8036cc3-bddc-47d7-9686-bbea50bc7f1c"/>
<textFieldExpression><![CDATA[$F{ASNDETAILID}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="210" y="0" width="100" height="30" uuid="5f3a97c2-6f8e-4458-8f9e-c13890a6b308"/>
<textFieldExpression><![CDATA[$F{LINENBR}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band height="10" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="7" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="8" splitType="Stretch"/>
</summary>
</jasperReport>
I am open to all suggestions... again, very little experience with JSON and Jasper... especially around subreports... I was hoping I would not even need a subreport.
In Subreport, delete all bands except column header and detail .
from properties, make all the margins to zero.
In main report, make column header height = field height
and delete all other bands.
This is all basic alignment.

Results of 2 groups through eachother

I have 2 groups, both will show the same 2 records (from the sql output) but grouped differently and shows different fields.
Output:
The 2nd result of group 1 is between the results of group 2. This is how Jaspersoft works.
But does someone have an idea how to keep the group results with eachother?
Group 1: result 1
Group 1: result 2
Group 2: result 1
Group 2: result 2
Any help or tips are appreciated.
[1]https://i.stack.imgur.com/509cP.jpg
Jrxml
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.2.2.final using JasperReports Library version 4.7.0 -->
<!-- 2017-08-11T16:19:29 -->
<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="Blank_A4_3" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="a75576f0-e223-4e8a-8d52-67936178ea31">
<property name="com.jaspersoft.studio.data.sql.tables" value=""/>
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="test"/>
<queryString>
<![CDATA[]]>
</queryString>
<field name="from_name" class="java.lang.String"/>
<field name="from_name2" class="java.lang.String"/>
<field name="undgcode" class="java.lang.String"/>
<field name="product_item_id" class="java.lang.String"/>
<group name="Group1">
<groupExpression><![CDATA[$F{product_item_id}]]></groupExpression>
<groupHeader>
<band height="50" splitType="Prevent">
<textField>
<reportElement isPrintRepeatedValues="false" x="40" y="10" width="220" height="30" uuid="ce52a200-b3dd-4b9b-bee4-30cc9db15aa5"/>
<textFieldExpression><![CDATA[$F{from_name}]]></textFieldExpression>
</textField>
</band>
</groupHeader>
</group>
<group name="Group2" keepTogether="true">
<groupExpression><![CDATA[$F{undgcode}]]></groupExpression>
<groupHeader>
<band height="64">
<staticText>
<reportElement x="140" y="10" width="100" height="30" uuid="28d2e565-98d6-4714-8420-81a3819ab46a"/>
<text><![CDATA[Static Text]]></text>
</staticText>
</band>
</groupHeader>
<groupFooter>
<band height="50" splitType="Prevent">
<textField>
<reportElement isPrintRepeatedValues="false" x="40" y="10" width="220" height="30" uuid="857197bd-e4b6-404b-a527-19e63dd02a94">
<property name="com.jaspersoft.studio.unit.x" value="pixel"/>
</reportElement>
<textFieldExpression><![CDATA[$F{from_name2}]]></textFieldExpression>
</textField>
</band>
</groupFooter>
</group>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch"/>
</title>
<pageHeader>
<band height="35" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="61" splitType="Stretch"/>
</columnHeader>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>

SubReport not shown

I'd like to create a simple Jasper Report, with subreport, but I cannot make it work.
For example, I have two, simple report.
test1.jrxml
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.2.0.final using JasperReports Library version 6.2.0 -->
<!-- 2016-01-18T23:29:14 -->
<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="test1" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="553ce57f-5ea7-48e5-8eaa-dcfecf31880a">
<queryString>
<![CDATA[select dummy from dual]]>
</queryString>
<field name="dummy" class="java.lang.String"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch"/>
</title>
<pageHeader>
<band height="35" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="61" splitType="Stretch">
<staticText>
<reportElement x="89" y="0" width="100" height="30" uuid="04f9b63d-265b-45f0-a249-41464df6b4c0"/>
<text><![CDATA[x]]></text>
</staticText>
<staticText>
<reportElement x="227" y="0" width="100" height="30" uuid="0c7db454-653c-4dcf-af94-a0f1c9962b91"/>
<text><![CDATA[x]]></text>
</staticText>
<staticText>
<reportElement x="352" y="0" width="100" height="30" uuid="7ad861d5-74ba-49e9-95c7-4cd01d184dbe"/>
<text><![CDATA[x]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="257" splitType="Stretch">
<textField>
<reportElement x="89" y="66" width="100" height="30" uuid="4099071d-8bfc-4e61-a697-af078ccb626a"/>
<textFieldExpression><![CDATA[$F{dummy}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="227" y="68" width="100" height="30" uuid="a955ca4e-aecd-48c3-8b7c-face6295b879"/>
<textFieldExpression><![CDATA[$F{dummy}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="352" y="65" width="100" height="30" uuid="5a998443-ae4f-457d-a565-67b4f3405951"/>
<textFieldExpression><![CDATA[$F{dummy}]]></textFieldExpression>
</textField>
<subreport>
<reportElement x="555" y="57" width="200" height="200" uuid="d6eada20-a566-4ba5-ab51-9d6ea0b4dfd9"/>
<parametersMapExpression><![CDATA[$P{REPORT_PARAMETERS_MAP}]]></parametersMapExpression>
<subreportParameter name="a">
<subreportParameterExpression><![CDATA[12]]></subreportParameterExpression>
</subreportParameter>
<subreportExpression><![CDATA["test4.jasper"]]></subreportExpression>
</subreport>
</band>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>
test4.jrxml
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.2.0.final using JasperReports Library version 6.2.0 -->
<!-- 2016-01-18T23:27:56 -->
<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="test4" pageWidth="842" pageHeight="595" orientation="Landscape" columnWidth="802" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="c55e71d8-6eb9-4f20-9263-c50c295fa0d1">
<parameter name="a" class="java.lang.String"/>
<queryString>
<![CDATA[select dummy from dual where 1=1]]>
</queryString>
<field name="dummy" class="java.lang.String"/>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch"/>
</title>
<pageHeader>
<band height="35" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="61" splitType="Stretch">
<staticText>
<reportElement x="364" y="0" width="100" height="30" uuid="1d48df0f-3f4c-489f-b479-e981b2727590"/>
<text><![CDATA[b]]></text>
</staticText>
<staticText>
<reportElement x="478" y="0" width="100" height="30" uuid="397b1c60-fe4d-4f41-a7a4-7c585a57ac15"/>
<text><![CDATA[a]]></text>
</staticText>
</band>
</columnHeader>
<detail>
<band height="125" splitType="Stretch">
<staticText>
<reportElement x="239" y="58" width="100" height="30" uuid="5b5c86c0-1b1b-44d3-87cb-2ad2782a3408"/>
<text><![CDATA[test4]]></text>
</staticText>
<textField>
<reportElement x="364" y="66" width="100" height="30" uuid="d3217648-88a1-4d88-b2b0-7f7cc4e598c6"/>
<textFieldExpression><![CDATA[$F{dummy}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="478" y="47" width="100" height="30" uuid="f2c6bfb9-ee73-4928-8ce4-0a83060d0801"/>
<textFieldExpression><![CDATA[$F{dummy}]]></textFieldExpression>
</textField>
</band>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>
The selects provide one result (the DB is Oracle), but the subreport isn't visible in the repport made from test1.jrxml. But a whole new, empty page is at the end of the report.
Can you show me what's wrong with this example? I'd tried a lot's of stuff (default value in the subreport, When No Data = All Sections, No Detail setting in the subReport's header, and a lot of stuff, I can't remember), but nothing helped.
In your example I can see two problems:
You need to pass absolute path to subreport (this is normally done by parameter, so that it can be controlled on runtime)
<parameter name="SUBREPORT_DIR" class="java.lang.String" isForPrompting="false">
<defaultValueExpression><![CDATA["C:\\jdd\\projects\\StackTrace\\jasper\\"]]></defaultValueExpression>
</parameter>
<subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "test4.jasper"]]></subreportExpression>
You need to pass the report connection to the subreport
<subreport>
<reportElement x="555" y="57" width="200" height="200" uuid="d6eada20-a566-4ba5-ab51-9d6ea0b4dfd9"/>
<parametersMapExpression><![CDATA[$P{REPORT_PARAMETERS_MAP}]]></parametersMapExpression>
<subreportParameter name="a">
<subreportParameterExpression><![CDATA[12]]></subreportParameterExpression>
</subreportParameter>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
<subreportExpression><![CDATA[$P{SUBREPORT_DIR} + "test4.jasper"]]></subreportExpression>
</subreport>

How to pass a parameter from main report to sub report?

I want to pass my parameter value from main report to the sub report.
I have tried many ways. Also I have tried options from this link as well
passing-parameters-from-main-report-to-subreport-to-subreport-in-jasper
Main report
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.2.0.final using JasperReports Library version 6.2.0 -->
<!-- 2016-01-03T00:04:36 -->
<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="parademo" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="4949f116-97b5-453c-8581-61ccb1b3159e">
<parameter name="TITLEPARA" class="java.lang.String" isForPrompting="false">
<defaultValueExpression><![CDATA["hi title"]]></defaultValueExpression>
</parameter>
<queryString>
<![CDATA[]]>
</queryString>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch">
<textField>
<reportElement x="180" y="36" width="220" height="30" uuid="4ac55979-2248-45d2-a001-3c82b5fec56b"/>
<textFieldExpression><![CDATA[$P{TITLEPARA}]]></textFieldExpression>
</textField>
</band>
</title>
<pageHeader>
<band height="35" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="61" splitType="Stretch"/>
</columnHeader>
<detail>
<band height="286" splitType="Stretch">
<subreport runToBottom="false">
<reportElement x="0" y="86" width="560" height="74" uuid="eca8556b-2d65-462f-a3d3-ac95ea6e3ebf"/>
<subreportParameter name="TITLEPARA">
<subreportParameterExpression><![CDATA[$P{TITLEPARA}]]></subreportParameterExpression>
</subreportParameter>
<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
<subreportExpression><![CDATA["file:/home/rectrix/workspace/jasper/subparam.jrxml"]]></subreportExpression>
</subreport>
</band>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>
Sub-Report
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.2.0.final using JasperReports Library version 6.2.0 -->
<!-- 2016-01-03T00:04:17 -->
<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="subparam" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="b4c019e3-0dc2-425c-b449-908c4fd21bde">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="MainReportDataSet"/>
<parameter name="TITLEPARA" class="java.lang.String" isForPrompting="false"/>
<queryString>
<![CDATA[]]>
</queryString>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch">
<textField>
<reportElement x="140" y="45" width="100" height="30" uuid="6b9d5038-4163-47ed-a0cd-812f07b27ff0"/>
<textFieldExpression><![CDATA[$P{TITLEPARA}]]></textFieldExpression>
</textField>
</band>
</title>
<pageHeader>
<band height="35" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="61" splitType="Stretch"/>
</columnHeader>
<detail>
<band height="125" splitType="Stretch"/>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
</jasperReport>
I am able to print "HI TITLE" Using the parameter in my main report's title band.
I want to pass this value to the sub-report using the parameter and print it on the title band of the sub-report.
I want to pass this value using a parameter only, because I want to know how the parameters works so I could use it for my project to pass the values to sub-report through parameters.
You are passing the parameter correctly, this is not your issue.
Using your example files you have these issues.
If the datasource is empty you need attribute whenNoDataType="AllSectionsNoDetail" on jasperReport tag to display something (both in main and subreport).
The subreport can not be in the detail band (since your datasource is empty), move it into another band example title band.
You can not reference a jrxml in subreportExpression, you need to reference a .jasper file (the jrxml when it has been complied). Note: the path need's to be the absolute path to the file (you normally use a parameter for this so that you can pass it in runtime)
see this for more information on path to subreport Subreport not rendering in main report
For testing I suggest you to put another static text element in the subreport, so that you understand if the subreport is displayed or not.

JasperReports collection as datasource?

I'm trying to find out how to use a string collection as a datasource in JasperReports.
I guess I found the solution, but I can't get this to work, can anyone assist me?
set as datasource the special data source JREmptyDatasource( $F{my_collection}.size() )
This creates an empty data set with the same size of records as the collection.
Pass the $F{my_collection} as parameter to the sub dataset (using the data set run of the List).
To print the current element of the collection:
$P{my_collection_param}.get( $V{REPORT_COUNT} )
<?xml version="1.0" encoding="UTF-8"?>
<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="report1" language="groovy" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
<property name="ireport.zoom" value="1.0"/>
<property name="ireport.x" value="0"/>
<property name="ireport.y" value="0"/>
<subDataset name="dataset1">
<parameter name="my_collection_param" class="java.util.Collection" isForPrompting="false">
<defaultValueExpression><![CDATA[$P{my_collection}]]></defaultValueExpression>
</parameter>
</subDataset>
<parameter name="my_collection" class="java.util.Collection">
<defaultValueExpression><![CDATA["anna"]]></defaultValueExpression>
</parameter>
<field name="my_collection" class="java.util.Collection">
<fieldDescription><![CDATA[]]></fieldDescription>
</field>
<background>
<band splitType="Stretch"/>
</background>
<title>
<band height="79" splitType="Stretch"/>
</title>
<pageHeader>
<band height="35" splitType="Stretch"/>
</pageHeader>
<columnHeader>
<band height="61" splitType="Stretch"/>
</columnHeader>
<detail>
<band height="125" splitType="Stretch">
<componentElement>
<reportElement x="51" y="30" width="400" height="50"/>
<jr:list xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd" printOrder="Vertical">
<datasetRun subDataset="dataset1">
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource($F{my_collection}.size())]]></dataSourceExpression>
</datasetRun>
<jr:listContents height="50" width="0">
<textField>
<reportElement x="159" y="24" width="100" height="20"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$P{my_collection_param}.get( $V{REPORT_COUNT} )]]></textFieldExpression>
</textField>
</jr:listContents>
</jr:list>
</componentElement>
</band>
</detail>
<columnFooter>
<band height="45" splitType="Stretch"/>
</columnFooter>
<pageFooter>
<band height="54" splitType="Stretch"/>
</pageFooter>
<summary>
<band height="42" splitType="Stretch"/>
</summary>
I guess your hack of using JREmptyDataSource is good by definition, if it works.
But you'll find that things are lot easier if you use this instead:
new net.sf.jasperreports.engine.data.JRMapCollectionDataSource($P{my_collection_param})