簡體   English   中英

該表在Jasper Report Java bean中不可見

[英]Table is not visible in Jasper Report Java bean

我在Jasper報告(數據源Java bean)中制作了一個簡單的報告。 我正在報表中制作一張桌子。 在jaspersoft studio中,該表是可見的,但是當我生成報告時,該表是不可見的,其余條目都是正確且可見的。 我已在“詳細信息”部分添加了表格。
xml代碼:

<subDataset name="TableDataSet" uuid="c661db1a-6eb7-45f7-9b83-60d1e897aa6e">
        <queryString>
            <![CDATA[]]>
        </queryString>
        <field name="parts" class="java.util.List">
            <fieldDescription><![CDATA[parts]]></fieldDescription>
        </field>
        <field name="width" class="java.lang.Double">
            <fieldDescription><![CDATA[width]]></fieldDescription>
        </field>
        <field name="length" class="java.lang.Double">
            <fieldDescription><![CDATA[length]]></fieldDescription>
        </field>
    </subDataset>
<componentElement>
                <reportElement x="213" y="289" width="140" height="60" uuid="d189551d-deb4-4dd2-8124-7d6f98fa8a5f">
                    <property name="com.jaspersoft.studio.layout" value="com.jaspersoft.studio.editor.layout.grid.JSSGridBagLayout"/>
                    <property name="com.jaspersoft.studio.table.style.table_header" value="Table_TH"/>
                    <property name="com.jaspersoft.studio.table.style.column_header" value="Table_CH"/>
                    <property name="com.jaspersoft.studio.table.style.detail" value="Table_TD"/>
                    <property name="net.sf.jasperreports.export.headertoolbar.table.name" value="Parts Table"/>
                </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="TableDataSet" uuid="d2e7599c-305c-462e-b6ed-a41a271e055f">
                        <connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
                    </datasetRun>
                    <jr:column width="40" uuid="a0e059cc-643c-4015-a824-c6612add40cf">
                        <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column1"/>
                        <jr:columnHeader height="30" rowSpan="1">
                            <staticText>
                                <reportElement x="0" y="0" width="40" height="30" uuid="f0b3d3da-0e18-4873-83d6-7b88bb183a10"/>
                                <text><![CDATA[Parts]]></text>
                            </staticText>
                        </jr:columnHeader>
                        <jr:detailCell height="30">
                            <textField>
                                <reportElement x="0" y="0" width="40" height="30" uuid="af940dbe-df85-4655-83c3-50c57b2108a1"/>
                                <textFieldExpression><![CDATA[$F{parts}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                    <jr:column width="60" uuid="cc40141d-88d3-40f7-8170-ca977bf9290b">
                        <property name="com.jaspersoft.studio.unit.width" value="pixel"/>
                        <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column2"/>
                        <jr:columnHeader height="30" rowSpan="1">
                            <staticText>
                                <reportElement x="0" y="0" width="60" height="30" uuid="fbd64c97-d94c-4708-afc9-87a49ae1329f"/>
                                <text><![CDATA[Length]]></text>
                            </staticText>
                        </jr:columnHeader>
                        <jr:detailCell height="30">
                            <textField>
                                <reportElement x="0" y="0" width="60" height="30" uuid="4ecc0959-fd6d-4e78-8987-c83c754edff4"/>
                                <textFieldExpression><![CDATA[$F{length}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                    <jr:column width="40" uuid="5dc3cf98-b681-4e63-88c1-38bd8f089e04">
                        <property name="com.jaspersoft.studio.components.table.model.column.name" value="Column3"/>
                        <jr:columnHeader height="30" rowSpan="1">
                            <staticText>
                                <reportElement x="0" y="0" width="40" height="30" uuid="346fa23f-c442-4800-967c-741b2303c13e"/>
                                <text><![CDATA[Width]]></text>
                            </staticText>
                        </jr:columnHeader>
                        <jr:detailCell height="30">
                            <textField>
                                <reportElement x="0" y="0" width="40" height="30" uuid="beee575e-17c4-402e-8246-68e2ccbc43f5"/>
                                <textFieldExpression><![CDATA[$F{width}]]></textFieldExpression>
                            </textField>
                        </jr:detailCell>
                    </jr:column>
                </jr:table>
            </componentElement>

Java代碼添加值

pattern.addPart("Door left", 1235, 445);
            pattern.addPart("Door right", 1235, 445);
            pattern.addPart("Top shelf", 1235, 445);
            pattern.addPart("Door right", 1235, 445);
            pattern.addPart("Door left", 1235, 445);
            pattern.addPart("Top shelf", 1235, 445);

我按照上幾個崗位SO 這里這一個 ,但沒有任何工程。 編譯jrxml文件后,我可以在Jaspersoft Studio的“預覽”部分中看到該表,但是在生成報告時看不到。
有什么幫助嗎?

發生這種情況可能有幾個原因。 例如:


表屬性

表屬性


報告屬性

“沒有細節”聽起來有點瘋狂,但是此報告配置也可以解決問題

報告屬性


您需要將字段的集合傳遞給報告

ArrayList<YourReportObject> reportData = new ArrayList<>();
reportData.add(new YourReportObject());

從集合中創建一個JRDataSource

JRDataSource dataSource = new JRBeanCollectionDataSource(reportData);

並使用dataSource作為參數填充報表

JasperPrint jasperPrint = JasperFillManager.fillReport(report, parameters, dataSource);

確保YourReportObject包含所有$F{...}字段。 變量名稱必須相等!

這里是更多示例: http : //jasperreports.sourceforge.net/sample.reference/datasource/

經過這篇文章解決了我的問題。 我忘了在jr:table組件處傳遞數據源。

jrxml中進行的更正:

<subDataset name="Dataset1">
    <queryString>
        <![CDATA[]]>
    </queryString>
    <field name="part" class="java.lang.String">
        <fieldDescription><![CDATA[part]]></fieldDescription>
    </field>
    <field name="length" class="java.lang.Double">
        <fieldDescription><![CDATA[length]]></fieldDescription>
    </field>
    <field name="width" class="java.lang.Double">
        <fieldDescription><![CDATA[width]]></fieldDescription>
    </field>
</subDataset>

jr:table標簽中添加數據源表達式,如下所示:

<datasetRun subDataset="Dataset1">
    <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{parts})]]></dataSourceExpression>
</datasetRun>

這對我有用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM