9

是否可以在运行时jasper Reports加载ResourceBundle(for i18n)?

我想从 jrxml 文件(例如c:\reports\report.jrxml)创建一个报告
,我的标签位于 ( c:\messages\report.properties) 的属性文件中。

我只找到了属性文件在类加载器中的示例。

谢谢

4

2 回答 2

11

John Ferguson 的博客提到诀窍是REPORT_RESOURCE_BUNDLE使用自定义 ResourceBundle 实例覆盖参数。

// Compiling the report is not a necessary step; prefer using .jasper files
// that have been pre-compiled to avoid this compilation step.
//
JasperDesign jasperDesign = JasperManager.loadXmlDesign("Report.jrxml");
JasperReport jasperReport = JasperManager.compileReport(jasperDesign);

Map parameters = new HashMap();
parameters.put("REPORT_LOCALE",LocaleManager.currentLocale());
parameters.put("REPORT_RESOURCE_BUNDLE",resourceBundle);
Connection conn = DBConnectionFactory.getConnection();
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,
                                                       parameters,
                                                       conn);

resourceBundle可以来自任何地方。例如:

try(FileInputStream fis = new FileInputStream("/tmp/report.properties")) {
  ResourceBundle resourceBundle = new PropertyResourceBundle(fis);

  // Pass resourceBundle into the report, as shown above.
}
于 2013-03-11T13:49:43.083 回答
3

从资源包加载包:

ResourceBundle bundle=ResourceBundle.getBundle("/reports/bundles/bundle",Locale.CANADA_FRENCH);

填写报告::

 params.put("REPORT_RESOURCE_BUNDLE", bundle);
JasperPrint jasPrint = JasperFillManager.fillReport(reportStream, params, data);
于 2016-03-25T04:13:35.667 回答