JasperReports:Struts插件将Map作为参数传递

时间:2012-05-08 12:46:50

标签: struts2 jasper-reports

这是我的第一个问题!

我正在尝试将Map作为参数从struts操作传递到报表。我已在reportParameters地图中插入了传递给 jrxml 文件的地图。

我的问题是,是否可以在 jrxml 文件中检索此地图。

更确切地说,我声明如下:

<parameter name="reportParams.testMap" class="java.util.Map"/>

我希望像这样使用它:

<textField>
    <reportElement style="StyleData" x="240" y="0" width="100" height="23"/>
    <textElement textAlignment="Left" verticalAlignment="Top"/>
    <textFieldExpression><![CDATA[testMap.get("AR")]]></textFieldExpression>
</textField>

有可能吗?因为我在应用程序服务器日志中不断收到此错误:

No such property: testMap for class: Blank32A4_1336385977531_38171
Error evaluating expression : Source text : testMap.get("AR")
Error evaluating expression : Source text : testMap.get("AR")

我的动作类看起来像这样:

@Injectable
@Results({
@Result(name = "success", type = "jasper", params={"location",
    "report.jasper",
    "connection", "statsConnection",
    "dataSource", "translations",
    "reportParameters","reportParams",
    "format","PDF"})
})
public class LocalMapStatisticNewAction extends ActionSupport{

    ...

    public String execute() {
            reportParams = new Hashtable<String, Object>();
            testMap = new Hashtable<String, String>();
            testMap.put("AR", "Argentina");
            testMap.put("ES", "Spain");
            reportParams.put("testMap", testMap);

            //Jasper code here
    }

    ...

    public Map<String, Object> getReportParams() {
        return reportParams;
    }
}

任何提示都会有所帮助!

1 个答案:

答案 0 :(得分:0)

看起来它可能就像用错误的名称引用参数一样简单。

testMap.get("AR")

您没有名为testMap的参数。您有一个名为reportParams.testMap的参数。此外,您需要参考这样的参数:

$P{testMap}.get("AR")

重命名参数或重命名参数的参考,你应该没问题。