带收集参数的 Jasperserver 报告执行服务

发布于 2025-01-09 12:25:01 字数 3547 浏览 4 评论 0原文

当我尝试将多个值传递给请求正文中的集合类型参数时,我在生成 jasper 报告时遇到一些问题。 在我的融洽关系中,我的参数是这样描述的

<parameter name="skillList" class="java.util.Collection" nestedType="java.lang.String">
 <parameterDescription><![CDATA[list of skill]]></parameterDescription>
</parameter>

在 jaspersoft studio 中,当我尝试可视化我的报告并添加更多价值时,它运行良好并且生成了我的报告 输入图片这里的描述

但是,当我尝试使用 HTTP POST 的服务器执行服务和这样的请求正文时:

<reportExecutionRequest>
    <reportUnitUri>MyReportURI</reportUnitUri>
    <async>false</async>
    <outputFormat>pdf</outputFormat>
    <parameters>
        <reportParameter name="title">
            <value>--- titre test ---</value>
        </reportParameter>
        <reportParameter name="header">
            <value>@@@ header test @@@</value>
        </reportParameter>
        <reportParameter name="name">
            <value>LE TUTOUR</value>
        </reportParameter>
        <reportParameter name="surname">
            <value>Erwan</value>
        </reportParameter>
        <reportParameter name="skillList">
                <value>java</value>
                <value>maven</value>
        </reportParameter>
    </parameters>
</reportExecutionRequest>

如果我在 SkillList 参数中只有一个值,我的融洽关系就会很好地生成,但是当我添加另一个我有 HTTP 400 错误请求。

文档中该服务有很多示例具有多个值,因此我不明白为什么未生成我的报告。

如果有人有解决方案或遇到相同的问题并解决了它,我不会拒绝任何帮助。

编辑 在一次新的尝试中,我更改了参数,它现在是一个子数据集

    <subDataset name="listSkill" uuid="8027f62e-3b29-4faf-b11a-185b4db46d6f">
            <field name="skill" class="java.lang.String">
                <fieldDescription><![CDATA[_THIS]]></fieldDescription>
            </field>

</subDataset>

,当我生成报告时,使用它的方式

<componentElement>
                <reportElement x="0" y="200" width="100" height="30" uuid="26b52f0f-e1e0-451e-9183-2df0f1f1ce65"/>
                <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">
                    <datasetRun subDataset="listSkill" uuid="593d4d96-cbaf-46ba-94ef-97344e0cb4f2">
                        <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($P{skills}) ]]></dataSourceExpression>
                    </datasetRun>
                    <jr:listContents height="30" width="100">
                        <textField>
                            <reportElement x="0" y="0" width="100" height="30" uuid="061f84d9-205a-4f49-a711-1f657b1fa5fd"/>
                            <textFieldExpression><![CDATA[$F{skill}]]></textFieldExpression>
                        </textField>
                    </jr:listContents>
                </jr:list>
            </componentElement>

仍然可以在 jaspersoft studio 中工作,但在尝试使用服务器的 REST API 执行它时则不行。

I have some trouble generating jasper report when i try to pass more than on value to a collection type parameter in my request body.
In my rapport my parameter is decribed like this

<parameter name="skillList" class="java.util.Collection" nestedType="java.lang.String">
 <parameterDescription><![CDATA[list of skill]]></parameterDescription>
</parameter>

In jaspersoft studio when i tried to visualize my report and add more value it work well and my report is generated
enter image description here

But when i try to use the execution service of the server using HTTP POST with a request body like this one :

<reportExecutionRequest>
    <reportUnitUri>MyReportURI</reportUnitUri>
    <async>false</async>
    <outputFormat>pdf</outputFormat>
    <parameters>
        <reportParameter name="title">
            <value>--- titre test ---</value>
        </reportParameter>
        <reportParameter name="header">
            <value>@@@ header test @@@</value>
        </reportParameter>
        <reportParameter name="name">
            <value>LE TUTOUR</value>
        </reportParameter>
        <reportParameter name="surname">
            <value>Erwan</value>
        </reportParameter>
        <reportParameter name="skillList">
                <value>java</value>
                <value>maven</value>
        </reportParameter>
    </parameters>
</reportExecutionRequest>

If I have only one value in the skillList parameter my rapport is well generated, but when I add another one I have a HTTP 400 bad request.

In the documentation of the service there is many exemple with more than one value so i don't understand why my repport is not generated.

If someone have a solution or have encountered the same issue and solved it i woul not say no to some help.

edit
In a new attempt I changed my parameter, it's now a subdataset

    <subDataset name="listSkill" uuid="8027f62e-3b29-4faf-b11a-185b4db46d6f">
            <field name="skill" class="java.lang.String">
                <fieldDescription><![CDATA[_THIS]]></fieldDescription>
            </field>

</subDataset>

and the way to use it

<componentElement>
                <reportElement x="0" y="200" width="100" height="30" uuid="26b52f0f-e1e0-451e-9183-2df0f1f1ce65"/>
                <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">
                    <datasetRun subDataset="listSkill" uuid="593d4d96-cbaf-46ba-94ef-97344e0cb4f2">
                        <dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($P{skills}) ]]></dataSourceExpression>
                    </datasetRun>
                    <jr:listContents height="30" width="100">
                        <textField>
                            <reportElement x="0" y="0" width="100" height="30" uuid="061f84d9-205a-4f49-a711-1f657b1fa5fd"/>
                            <textFieldExpression><![CDATA[$F{skill}]]></textFieldExpression>
                        </textField>
                    </jr:listContents>
                </jr:list>
            </componentElement>

still work in jaspersoft studio when I generate my report, but not when in try to execute it, using the REST API of the server.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风吹过旳痕迹 2025-01-16 12:25:01

解决了这个问题:

现在我只将 1 个参数传递给我的 rapport,这是一个 json 字符串,其中所有参数都作为字段。

我使用与该字符串匹配的数据适配器,并将所有 $P{xxxx} 替换为 $F{xxxx}。

然后,我使用报告的 JSON_INPUT_STREAM 参数将该字符串转换为字节数组输入流。

在此 json 字符串中,我的列表对象是这样描述的

"LIST_SKILL": [
    ["skill one", "value 1"],
    ["skill two", "value 2"],
    ["skill three", "value 3"]
]

然后在我的列表对象上的 dataSet 属性::JRDatasource 表达式中

((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("LIST_SKILL")

之后,我的报告在 jaspersoft studio / 服务器中正确生成,并通过其余服务调用。

Solved this:

Now I only pass 1 parameter to my rapport, a json string with all my parameters as fields.

I use a data adapter that match that string and replaced all the $P{xxxx} by $F{xxxx}.

Then I use the JSON_INPUT_STREAM parameter of the report to cast that string to byte array input stream.

In this json string, my lists object are described like this

"LIST_SKILL": [
    ["skill one", "value 1"],
    ["skill two", "value 2"],
    ["skill three", "value 3"]
]

Then on my list object, in the dataSet properties::JRDatasource expression

((net.sf.jasperreports.engine.data.JsonDataSource)$P{REPORT_DATA_SOURCE}).subDataSource("LIST_SKILL")

After that, my report is correctly generated in jaspersoft studio / server and with rest service call.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文