如何将参数传递给表组件? [英] How to pass parameter to the table component?

查看:50
本文介绍了如何将参数传递给表组件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Jaspersoft Studio创建报告,但发现将参数传递到表时遇到问题.

I am using Jaspersoft Studio to create the reports and I found a problem passing the parameters to a table.

报告布局和结果

正如您在这些图片中看到的那样,当我尝试使用参数设置表头时,我得到了null.

As you can see in these pictures, when I try to use the parameters to set the table headers I get null.

为了获取值,我在报表参数列表和表数据集参数列表中创建了相同的参数名称.显然,它根本不起作用.

In order to get the values, I created the same parameter names in both, the report parameters list and the tables dataset parameters list. Obviously, it didn't work at all.

我尝试遵循以下说明: jaspersoft-passing -参数表

I tried to follow these instructions: jaspersoft-passing-parameter-to-tables

但是我的数据源来自net.sf.jasperreports.engine.data.JRBeanCollectionDataSource参数,我找不到成功完成本教程的方法.

But my datasource is from a net.sf.jasperreports.engine.data.JRBeanCollectionDataSource parameter and I couldn't find the way to complete the tutorial successfully.

相关代码:

<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="subreport" pageWidth="555" pageHeight="802" columnWidth="555" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="19165c65-293a-42f1-9c92-0f4ceacaaa39">
  .....
  <subDataset name="ATableDataset" uuid="f7f9da25-c513-46bb-92c2-5a97ee76eb5e">
    <parameter name="tableHeadA" class="java.lang.String"/>
    <parameter name="column1AHead" class="java.lang.String"/>
    <parameter name="column2AHead" class="java.lang.String"/>
    <parameter name="column3AHead" class="java.lang.String"/>
    <queryString>
        <![CDATA[]]>
    </queryString>
    <field name="column1A" class="java.lang.String"/>
    <field name="column2A" class="java.lang.String"/>
    <field name="column3A" class="java.lang.String"/>
  </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">
    <datasetRun subDataset="ATableDataset" uuid="8ac10f33-c9e3-4678-8280-2830a76f72c6">
    <dataSourceExpression><![CDATA[$P{AtableDatasource}]]></dataSourceExpression>
   </datasetRun>
    ....
</jr:table>
......
</jasperReport>

完整代码,请参见 gitHub sample\src\main\resources\subreport.jrxml

推荐答案

要将参数传递给表组件,您需要:

To pass a parameter to a table component you need to:

1.在数据源中使用所需的类定义参数

示例

<subDataset name="TableDataset" uuid="da383fc2-e830-42d2-a822-6a65972efe4c">
    <parameter name="myParameter" class="java.lang.String"/>
     .......
</subDataset>

2.使用datasetParameter标记

示例

<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="5c37a139-a9dc-4f1b-b231-5dd82794ae4f">
       <datasetParameter name="myParameter">
             <datasetParameterExpression><![CDATA[$P{reportParameter}]]></datasetParameterExpression>
       </datasetParameter>
        <dataSourceExpression><![CDATA[....]]></dataSourceExpression>
   </datasetRun>
    ......
</jr:table>

在您的代码中,我找到1但没有找到2.

In your code I found 1 but not 2.

这篇关于如何将参数传递给表组件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆