jasper Reports
是否可以在运行时加载ResourceBundle
(对于i18n
)?
我想从jrxml文件创建报告(例如c:\reports\report.jrxml
)
我的标签位于(c:\messages\report.properties
)的属性文件中。
我只找到了属性文件在类加载器中的示例。
谢谢
最佳答案
John Ferguson's blog提到技巧是使用自定义ResourceBundle实例覆盖REPORT_RESOURCE_BUNDLE
参数。
// 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.
}
关于internationalization - 如何在运行时加载jasperreports resourcebundle?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15339158/