Struts2 jasperreports - 传递导出参数 [英] Struts2 jasperreports - passing export parameters
问题描述
我正在使用struts2 jasperreports插件,效果很好。问题是我想传递exportParameters,我不知道如何通过插件来做到这一点。
I'm using the struts2 jasperreports plugin and it works well. The problem is that I want to pass exportParameters and I'm not sure how to do that through the plugin.
推荐答案
哪个版本你使用的Struts2使用 2.1.2 +
它提供的功能提供 exportParameters
Which version of Struts2 you are using starting with 2.1.2+
it provides the feature to provides exportParameters
您需要在动作类中的struts配置文件中添加以下条目或类似条目
All you need to add following entry or similar entry in your struts config file inside your action class
<action name="myJasperTest" class="com.acme.test.action.JasperAction">
<result name="success" type="jasper">
<param name="location">foo.jasper</param>
<param name="dataSource">mySource</param>
<param name="exportParameters ">exportParameters </param>
</result>
</action>
exportParameters - 用于从中检索JR导出器参数的映射的OGNL表达式价值堆栈
。导出参数用于自定义JR导出。例如,PDF导出可能启用加密并将用户密码设置为报表创建者已知的字符串。
你需要在你的动作类中为你的导出参数定义一个地图,并提供它的getter / setter,而不是如上所述使用它的引用。
exportParameters - OGNL expression used to retrieve a map of JR exporter parameters from the value stack
. The export parameters are used to customize the JR export. For example, a PDF export might enable encryption and set the user password to a string known to the report creator.
All you need to define a map for your export parameters in your action class and provides its getter/setter than use its reference as described.
详情请参阅此网址
**Update**
以下是他们在结果类型中的表现方式
Here is how they have done it in result type
exporter = new JRXlsExporter();
Map exportParams = (Map) stack.findValue(exportParameters);
if (exportParams != null) {
LOG.debug("Found export parameters; adding to exporter parameters...");
exporter.getParameters().putAll(exportParams);
}
所以他们做的是他们试图找出 map
在值堆栈中,名称为 exportParameters
如果他们发现它们正在添加它。所以必须在你的动作类中执行此操作
so what they did is they tried to find out a map
in value stack with name exportParameters
if they find it they are adding it.So have to do this in your action class
Map<String,String> exportParameters= //init your map here
在此地图中设置您的属性并为其创建一个getter和setter此属性
set your properties in this map and create a getter and setter for this property
getExportParameters()
setExportParameters()
并在你的struts配置文件中声明地图如下
and in your struts config file declare the map as follows
<param name="exportParameters ">exportParameters </param>
休息框架将照顾
希望这会帮助你
rest framework will take care Hope this will help you
这篇关于Struts2 jasperreports - 传递导出参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!