2

I am trying to use a javabean list in a subreport that has a 2 fields along with getters and setters declared as

public class ProjectEventBean implements java.io.Serializable {
    private int projectId;
    private List<EventCostEntity> eventCostObjectList= new ArrayList<EventCostEntity>(); 
}

my main report has the following

        <subreport>
            <reportElement x="4" y="460" width="564" height="58" uuid="2e209cbe-a44e-4664-b31c-5bd0971dfd6e"/>
            <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{eventCostObjectList})]]></dataSourceExpression>
            <subreportExpression><![CDATA[$P{SUBREPORT_DIR}.toString()+"/eventDetail2_Costs.jasper"]]></subreportExpression>
        </subreport>

which I think is the correct way of passing the list however I cannot figure out what I need to put in my subreport to be able to retrieve the appropriate entity values in EventCostEntity.

     <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="eventDetail2_Costs" pageWidth="612" pageHeight="792" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="c0905867-c90a-49e0-86c6-75dc8b0ae946">
<queryString>
    <![CDATA[]]>
</queryString>
<field name="eventCostObjectList" class="java.util.List">
    <fieldDescription><![CDATA[eventCostObjectList]]></fieldDescription>
</field>
<field name="name" class="java.lang.String">
    <fieldDescription><![CDATA[name]]></fieldDescription>
</field>
<field name="cost" class="java.math.BigDecimal">
    <fieldDescription><![CDATA[cost]]></fieldDescription>
</field>
<columnHeader>
    <band height="80" splitType="Stretch">
        <staticText>
            <reportElement x="-11" y="20" width="100" height="22" uuid="575d25b1-1ae6-4396-a874-b51393409bda"/>
            <textElement>
                <font size="12" isBold="true" isUnderline="true"/>
            </textElement>
            <text><![CDATA[Costs:]]></text>
        </staticText>
        <staticText>
            <reportElement x="0" y="60" width="100" height="20" uuid="5b824dd4-cd12-452e-ae3f-5e23e9d6b3d2"/>
            <text><![CDATA[Name:]]></text>
        </staticText>
        <staticText>
            <reportElement x="170" y="60" width="100" height="20" uuid="ca13b09f-2e1c-429f-881c-01ca6dad8c4a"/>
            <text><![CDATA[Costs]]></text>
        </staticText>
    </band>
</columnHeader>
<detail>
    <band height="125" splitType="Stretch">
        <textField>
            <reportElement x="0" y="0" width="160" height="30" uuid="b2d51e70-2846-4e2b-8d8a-a8e77c909606"/>
            <textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
        </textField>
        <textField>
            <reportElement x="170" y="0" width="100" height="30" uuid="53a43c1e-7b57-4416-b558-030ccff9c23b"/>
            <textFieldExpression><![CDATA[$F{cost}]]></textFieldExpression>
        </textField>
    </band>
</detail>
</jasperReport>

When I use Jaspersoft Studio I see the eventCostObjectList as a list and not as individual objects of EventCostEntity.

What am I missing in my subreport to use the individual objects in the list? here is my subreport

    <?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="eventDetail2_Costs" pageWidth="612" pageHeight="792" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="e2be79ab-b7a6-40e0-9024-b0c0bc3fa26f">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="EventCostEntity_DATAADAPTER.xml"/>
<style name="Table_TH" mode="Opaque" backcolor="#F0F8FF">
    <box>
        <pen lineWidth="0.5" lineColor="#000000"/>
        <topPen lineWidth="0.5" lineColor="#000000"/>
        <leftPen lineWidth="0.5" lineColor="#000000"/>
        <bottomPen lineWidth="0.5" lineColor="#000000"/>
        <rightPen lineWidth="0.5" lineColor="#000000"/>
    </box>
</style>
<style name="Table_CH" mode="Opaque" backcolor="#BFE1FF">
    <box>
        <pen lineWidth="0.5" lineColor="#000000"/>
        <topPen lineWidth="0.5" lineColor="#000000"/>
        <leftPen lineWidth="0.5" lineColor="#000000"/>
        <bottomPen lineWidth="0.5" lineColor="#000000"/>
        <rightPen lineWidth="0.5" lineColor="#000000"/>
    </box>
</style>
<style name="Table_TD" mode="Opaque" backcolor="#FFFFFF">
    <box>
        <pen lineWidth="0.5" lineColor="#000000"/>
        <topPen lineWidth="0.5" lineColor="#000000"/>
        <leftPen lineWidth="0.5" lineColor="#000000"/>
        <bottomPen lineWidth="0.5" lineColor="#000000"/>
        <rightPen lineWidth="0.5" lineColor="#000000"/>
    </box>
</style>
<style name="Table 1_TH" mode="Opaque" backcolor="#F0F8FF">
    <box>
        <pen lineWidth="0.5" lineColor="#000000"/>
        <topPen lineWidth="0.5" lineColor="#000000"/>
        <leftPen lineWidth="0.5" lineColor="#000000"/>
        <bottomPen lineWidth="0.5" lineColor="#000000"/>
        <rightPen lineWidth="0.5" lineColor="#000000"/>
    </box>
</style>
<style name="Table 1_CH" mode="Opaque" backcolor="#BFE1FF">
    <box>
        <pen lineWidth="0.5" lineColor="#000000"/>
        <topPen lineWidth="0.5" lineColor="#000000"/>
        <leftPen lineWidth="0.5" lineColor="#000000"/>
        <bottomPen lineWidth="0.5" lineColor="#000000"/>
        <rightPen lineWidth="0.5" lineColor="#000000"/>
    </box>
</style>
<style name="Table 1_TD" mode="Opaque" backcolor="#FFFFFF">
    <box>
        <pen lineWidth="0.5" lineColor="#000000"/>
        <topPen lineWidth="0.5" lineColor="#000000"/>
        <leftPen lineWidth="0.5" lineColor="#000000"/>
        <bottomPen lineWidth="0.5" lineColor="#000000"/>
        <rightPen lineWidth="0.5" lineColor="#000000"/>
    </box>
</style>
<subDataset name="Dataset1" uuid="f42721f5-97f6-4d0b-8769-15899abedf7d">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
    <queryString>
        <![CDATA[]]>
    </queryString>
    <field name="name" class="java.lang.String">
        <fieldDescription><![CDATA[]]></fieldDescription>
    </field>
    <field name="cost" class="java.math.BigDecimal">
        <fieldDescription><![CDATA[]]></fieldDescription>
    </field>
</subDataset>
<queryString>
    <![CDATA[]]>
</queryString>
<background>
    <band splitType="Stretch"/>
</background>
<title>
    <band splitType="Stretch"/>
</title>
<pageHeader>
    <band splitType="Stretch"/>
</pageHeader>
<columnHeader>
    <band splitType="Stretch"/>
</columnHeader>
<detail>
    <band height="319" splitType="Stretch">
        <componentElement>
            <reportElement x="116" y="119" width="200" height="200" uuid="7ad39011-7d7e-4477-9b47-b243c2a97795">
                <property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.VerticalRowLayout"/>
            </reportElement>
            <jr:table xmlns:jr="http://jasperreports.sourceforge.net/jasperreports/components" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/components http://jasperreports.sourceforge.net/xsd/components.xsd">
                <datasetRun subDataset="Dataset1" uuid="5061a7f7-6c91-406c-9186-ddb3394facf6">
                    <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.JREmptyDataSource()]]></dataSourceExpression>
                </datasetRun>
                <jr:column width="100" uuid="07dae0b1-2020-4a45-a1c1-eeb849dad2c3">
                    <jr:tableHeader style="Table 1_TH" height="30"/>
                    <jr:columnHeader style="Table 1_CH" height="30">
                        <staticText>
                            <reportElement x="0" y="0" width="100" height="30" uuid="4c5989e0-cebe-48fa-b68b-1019d6595ec4"/>
                            <text><![CDATA[name]]></text>
                        </staticText>
                    </jr:columnHeader>
                    <jr:detailCell style="Table 1_TD" height="30">
                        <textField>
                            <reportElement x="0" y="0" width="100" height="30" uuid="46947bba-f80b-4bf1-bbc3-1ea3fafec171"/>
                            <textFieldExpression><![CDATA[$F{name}]]></textFieldExpression>
                        </textField>
                    </jr:detailCell>
                </jr:column>
                <jr:column width="100" uuid="be2b6e8c-5962-4629-b557-bfe58e0daff8">
                    <jr:tableHeader style="Table 1_TH" height="30"/>
                    <jr:columnHeader style="Table 1_CH" height="30">
                        <staticText>
                            <reportElement x="0" y="0" width="100" height="30" uuid="391f3ed4-8369-4b5f-ab69-83b46d4ec7d1"/>
                            <text><![CDATA[cost]]></text>
                        </staticText>
                    </jr:columnHeader>
                    <jr:detailCell style="Table 1_TD" height="30">
                        <textField>
                            <reportElement x="0" y="0" width="100" height="30" uuid="60b796f7-3d06-442a-8a87-a25ef027dc48"/>
                            <textFieldExpression><![CDATA[$F{cost}]]></textFieldExpression>
                        </textField>
                    </jr:detailCell>
                </jr:column>
            </jr:table>
        </componentElement>
    </band>
</detail>
<columnFooter>
    <band splitType="Stretch"/>
</columnFooter>
<pageFooter>
    <band splitType="Stretch"/>
</pageFooter>
<summary>
    <band splitType="Stretch"/>
</summary>

`

snafua
  • 75
  • 1
  • 14
  • Try using table in your subreport. Each row in the table would represent a single EventCostEntity. In this way it would be easy for you to display all the Event Cost entities. – PeaceIsPearl May 05 '16 at 20:07
  • Thanks, that's what I was looking for, however I am having a problem getting the dataset in the table to find the columns from EventCostEntity. Any suggestions – snafua May 06 '16 at 19:23
  • Sorry, but could you please be more clear on your question. – PeaceIsPearl May 06 '16 at 19:29
  • Sorry for not being clearer, When I add the table it requests a data adapter, I provide a static adapter that returns the EventCostEntity, however the Data Source says "this adapter does not provide any facility to retrieve the fields" therefore I do not get any columns in my dataset. What do I need to do to get the columns for the table? – snafua May 06 '16 at 20:34
  • Please share your code and the error trace – PeaceIsPearl May 06 '16 at 20:39
  • I am creating a new report with column header and detail. The error only shows in the table wizard where you Select the Datasource for a table, I have tested the datasource and it is successful . I am using Jasper Studio Standalone version 6.1.1. – snafua May 06 '16 at 21:29
  • You don't need a datasource. Keep it empty – PeaceIsPearl May 06 '16 at 21:49
  • The wizard first prompts for a dataset which I can choose empty dataset. The wizard then asks for a connection or datasource which I can choose empty datasource also. I still don't get any columns to choose from. SO I'm lost as to how to get a column in the table? – snafua May 06 '16 at 23:18
  • I added the sub report to this question with a table and two columns that I manually created via the dataset. I could never get JS to pull the fields via the table wizard. The fields are printing null. I am not sure how to connect the eventCostObjectList to the report. Thanks for your help in this matter. – snafua May 08 '16 at 15:37
  • @snafua [How to pass ArrayList to JasperReports?](http://stackoverflow.com/q/3624562/876298) - Did you check this way? Another post: [JRBeanCollectionDataSource: How to show data from the java.util.List from JavaBean?](http://stackoverflow.com/q/12209300/876298) – Alex K May 11 '16 at 15:18

0 Answers0