0

这是我在这里的第一个问题!

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

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

更准确地说,我这样声明:

<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;
    }
}

任何提示都会有所帮助!

4

1 回答 1

0

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

testMap.get("AR")

您没有名为testMap. 您有一个名为reportParams.testMap. 此外,您需要参考如下参数:

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

重命名参数或重命名参数的引用,应该没问题。

于 2012-05-08T16:19:43.347 回答