Jasper Studio重复块

时间:2016-11-23 07:27:58

标签: java jasper-reports

我有一个任务,创建JasperReoirts报告,其中包含动态重复块

这样的事情:

"You're cool guy because:
Reason:$F{reason}
Description: $F{desc}
Grade: $F{grade}
"

具有reason \ desc \ grade的块可以重复多次,具体取决于DTO对象中的java Collection。我应该使用哪种仪器?我尝试了列表,但它看起来像单个字段,而不是块。

例如: 我已经获得了jasper报告的DTO对象,其中包含对象列表List。列表中的此对象具有3个字符串字段(原因,描述,等级)。所以在报告中我想看到它像重复列表

中的每个元素
StopListReasons:
    Reason:  someReason1
    Description: someDescription1
    Grade: someGrade1

    Reason:  someReason2
    Description: someDescription2
    Grade: someGrade2

    Reason:  someReason3
    Description: someDescription3
    Grade: someGrade3 

我试图创建表格,哪一行包含3个标签和3个文本字段,但在预览时它是emtpty。我也在寻找List元素,但看起来它并不符合我的情况。

也许使用来自jrxml的代码,这个问题变得更加清晰

    <subDataset name="Dataset1" uuid="c5f7a5d1-6262-4003-a4fb-146ba8515c34">
    <property name="com.jaspersoft.studio.data.defaultdataadapter" value="adapter.xml"/>
    <queryString language="XPath">
        <![CDATA[/report/stopListInfos/slInfo]]>
    </queryString>
    <field name="stopListCode" class="java.lang.String">
        <fieldDescription><![CDATA[stopListCode]]></fieldDescription>
    </field>
    <field name="stopListResult" class="java.lang.String">
        <fieldDescription><![CDATA[stopListResult]]></fieldDescription>
    </field>
    <field name="clientType" class="java.lang.String">
        <fieldDescription><![CDATA[clientType]]></fieldDescription>
    </field>
</subDataset>

表格

            <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" whenNoDataType="AllSectionsNoDetail">
                <datasetRun subDataset="Dataset1" uuid="a5a0cf80-5aa6-415c-b31c-044bb856c70c">
                    <dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("/report/StopListInfos/slInfo")]]></dataSourceExpression>
                </datasetRun>
                <jr:column width="66" uuid="aa9f5289-56ad-47df-93cf-8a81770ecd4c">
                    <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column1"/>
                    <jr:detailCell style="Table_TD" height="110">
                        <staticText>
                            <reportElement x="0" y="0" width="66" height="38" uuid="9fa05583-38e1-4cd2-b717-7f953ed29042"/>
                            <text><![CDATA[1]]></text>
                        </staticText>
                        <staticText>
                            <reportElement x="0" y="38" width="66" height="36" uuid="915e8324-e9b9-452d-983c-3e241f34eb46"/>
                            <text><![CDATA[2]]></text>
                        </staticText>
                        <staticText>
                            <reportElement x="0" y="74" width="66" height="36" uuid="fc7a9e65-2573-405d-bd3f-c519bd93d162"/>
                            <text><![CDATA[3]]></text>
                        </staticText>
                    </jr:detailCell>
                </jr:column>
                <jr:column width="134" uuid="82a313a6-2d55-418e-af19-a3ff9439bd6a">
                    <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column2"/>
                    <jr:detailCell style="Table_TD" height="110">
                        <textField>
                            <reportElement x="0" y="0" width="134" height="38" uuid="003483c6-9aa4-43fe-8d8c-2a5aef9ccc3f"/>
                            <textFieldExpression><![CDATA[$F{stopListCode}]]></textFieldExpression>
                        </textField>
                        <textField>
                            <reportElement x="0" y="38" width="134" height="36" uuid="f3f7f9f6-7482-41a7-a473-0fa5d1a4bbed"/>
                            <textFieldExpression><![CDATA[$F{stopListResult}]]></textFieldExpression>
                        </textField>
                        <textField>
                            <reportElement x="0" y="74" width="134" height="36" uuid="8ca9059f-7c71-44ff-96fd-7b490d4f7c0e"/>
                            <textFieldExpression><![CDATA[$F{clientType}]]></textFieldExpression>
                        </textField>
                    </jr:detailCell>
                </jr:column>
            </jr:table>

1 个答案:

答案 0 :(得分:0)

解决方案是使用带有2列的表,该表的每一行包含3个静态&#34;行&#34;在第一列和3&#34;行&#34;在第二列中使用我的动态值。 在jrxml中它将是

                <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="c9a09593-11ee-4817-95f6-bd2903bdf820">
                        <datasetParameter name="ulInfo">
                            <datasetParameterExpression><![CDATA["ID Клиента в Мастер-системе – "+$F{clientId}+", ИНН – "+$F{inn} +", Наименование - " + $F{shortName}]]></datasetParameterExpression>
                        </datasetParameter>
                        <datasetParameter name="flInfo">
                            <datasetParameterExpression><![CDATA["ФИО - " + $F{clientFIO} + ", дата рождения - " + $F{clientBirthDate}]]></datasetParameterExpression>
                        </datasetParameter>
                        <dataSourceExpression><![CDATA[((net.sf.jasperreports.engine.data.JRXmlDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("/report/stopListInfos/slInfo")]]></dataSourceExpression>
                    </datasetRun>
                    <jr:column width="120" uuid="aa9f5289-56ad-47df-93cf-8a81770ecd4c">
                        <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column1"/>
                        <jr:detailCell style="Table_TD" height="80">
                            <staticText>
                                <reportElement x="0" y="0" width="120" height="20" uuid="9fa05583-38e1-4cd2-b717-7f953ed29042">
                                    <property name="com.jaspersoft.studio.unit.height" value="pixel"/>
                                </reportElement>
                                <textElement>
                                    <font fontName="Times New Roman" size="12" isBold="true"/>
                                </textElement>
                                <text><![CDATA[Код Стоп-листа:]]></text>
                            </staticText>
                            <staticText>
                                <reportElement x="0" y="20" width="120" height="20" uuid="915e8324-e9b9-452d-983c-3e241f34eb46"/>
                                <textElement>
                                    <font fontName="Times New Roman" size="12" isBold="true"/>
                                </textElement>
                                <text><![CDATA[Тип клиента:]]></text>
                            </staticText>
                            <staticText>
                                <reportElement x="0" y="40" width="120" height="20" uuid="fc7a9e65-2573-405d-bd3f-c519bd93d162">
                                    <property name="com.jaspersoft.studio.unit.height" value="pixel"/>
                                </reportElement>
                                <textElement>
                                    <font fontName="Times New Roman" size="12" isBold="true"/>
                                </textElement>
                                <text><![CDATA[Реквизиты клиента:]]></text>
                            </staticText>
                            <staticText>
                                <reportElement x="0" y="60" width="120" height="20" uuid="df0465cc-c3ab-4393-a12a-817c1ff749c7">
                                    <property name="com.jaspersoft.studio.unit.height" value="pixel"/>
                                </reportElement>
                                <textElement>
                                    <font fontName="Times New Roman" size="12" isBold="true"/>
                                </textElement>
                                <text><![CDATA[]]></text>
                            </staticText>
                        </jr:detailCell>
                    </jr:column>
                    <jr:column width="400" uuid="82a313a6-2d55-418e-af19-a3ff9439bd6a">
                        <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column2"/>
                        <jr:detailCell style="Table_TD" height="80">
                            <textField>
                                <reportElement x="0" y="0" width="400" height="20" uuid="003483c6-9aa4-43fe-8d8c-2a5aef9ccc3f"/>
                                <textElement>
                                    <font fontName="Times New Roman" size="12"/>
                                </textElement>
                                <textFieldExpression><![CDATA[$F{stopListCode} + " " +$F{stopListResult}]]></textFieldExpression>
                            </textField>
                            <textField>
                                <reportElement x="0" y="20" width="400" height="20" uuid="f3f7f9f6-7482-41a7-a473-0fa5d1a4bbed"/>
                                <textElement>
                                    <font fontName="Times New Roman" size="12"/>
                                </textElement>
                                <textFieldExpression><![CDATA[$F{clientType}]]></textFieldExpression>
                            </textField>
                            <textField>
                                <reportElement x="0" y="40" width="400" height="20" uuid="8ca9059f-7c71-44ff-96fd-7b490d4f7c0e">
                                    <property name="com.jaspersoft.studio.unit.height" value="pixel"/>
                                </reportElement>
                                <textElement>
                                    <font fontName="Times New Roman" size="12"/>
                                </textElement>
                                <textFieldExpression><![CDATA[$F{clientType}.equals("ЮЛ") ? $P{ulInfo} : $P{flInfo}]]></textFieldExpression>
                            </textField>
                            <staticText>
                                <reportElement x="0" y="60" width="400" height="20" uuid="19825a9f-d99a-4a98-b143-9fa91edc37a6">
                                    <property name="com.jaspersoft.studio.unit.height" value="pixel"/>
                                </reportElement>
                                <textElement>
                                    <font fontName="Times New Roman" size="12" isBold="true"/>
                                </textElement>
                                <text><![CDATA[]]></text>
                            </staticText>
                        </jr:detailCell>
                    </jr:column>
                </jr:table>

另外,我遇​​到了其他问题 - 如何从表中访问主报表字段。答案 - 使用表格数据集中的参数。