AbstractJasperReportsView only sets locale model attributes if not present already

This commit is contained in:
Juergen Hoeller 2010-10-20 05:22:43 +00:00
parent 244c96151e
commit d418eed56f
1 changed files with 6 additions and 3 deletions

View File

@ -568,7 +568,7 @@ public abstract class AbstractJasperReportsView extends AbstractUrlBasedView {
* Expose current Spring-managed Locale and MessageSource to JasperReports i18n * Expose current Spring-managed Locale and MessageSource to JasperReports i18n
* ($R expressions etc). The MessageSource should only be exposed as JasperReports * ($R expressions etc). The MessageSource should only be exposed as JasperReports
* resource bundle if no such bundle is defined in the report itself. * resource bundle if no such bundle is defined in the report itself.
* <p>Default implementation exposes the Spring RequestContext Locale and a * <p>The default implementation exposes the Spring RequestContext Locale and a
* MessageSourceResourceBundle adapter for the Spring ApplicationContext, * MessageSourceResourceBundle adapter for the Spring ApplicationContext,
* analogous to the <code>JstlUtils.exposeLocalizationContext</code> method. * analogous to the <code>JstlUtils.exposeLocalizationContext</code> method.
* @see org.springframework.web.servlet.support.RequestContextUtils#getLocale * @see org.springframework.web.servlet.support.RequestContextUtils#getLocale
@ -580,9 +580,12 @@ public abstract class AbstractJasperReportsView extends AbstractUrlBasedView {
*/ */
protected void exposeLocalizationContext(Map<String, Object> model, HttpServletRequest request) { protected void exposeLocalizationContext(Map<String, Object> model, HttpServletRequest request) {
RequestContext rc = new RequestContext(request, getServletContext()); RequestContext rc = new RequestContext(request, getServletContext());
if (!model.containsKey(JRParameter.REPORT_LOCALE)) {
model.put(JRParameter.REPORT_LOCALE, rc.getLocale()); model.put(JRParameter.REPORT_LOCALE, rc.getLocale());
}
JasperReport report = getReport(); JasperReport report = getReport();
if (report == null || report.getResourceBundle() == null) { if ((report == null || report.getResourceBundle() == null) &&
!model.containsKey(JRParameter.REPORT_RESOURCE_BUNDLE)) {
model.put(JRParameter.REPORT_RESOURCE_BUNDLE, model.put(JRParameter.REPORT_RESOURCE_BUNDLE,
new MessageSourceResourceBundle(rc.getMessageSource(), rc.getLocale())); new MessageSourceResourceBundle(rc.getMessageSource(), rc.getLocale()));
} }