Groovy Parameter Maps / Passing a locale to JasperReport

 

Hi,

I am using the jasperreports plugin and would like to pass the locale parameter to the reporting engine. There is a controller (jasper  controller) for generating reports which is called (by chaining) from another controller that assembles the data (MODEL_DATA). There is also a params map that holds additional parameters. The controller looks as follows:

import org.springframework.web.context.request.RequestContextHolder as RCH
import org.springframework.web.servlet.support.RequestContextUtils as RCU;
...
def report = {
Locale locale = RCU.getLocale(RCH.currentRequestAttributes().getRequest());
params.put("REPORT_LOCALE ", locale);
...
chain(controller:'jasper ',action:'index',model:[data:MODEL_DATA],params:params);
}

The important thing here is that the locale is actually instanceof java.util.Locale when it is put in the map.
However, later on I get a
java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Locale
at net.sf.jasperreports .engine.fill.JRFillDataset.setParameterValues(JRFillDataset.java:559)

The corresponding line reads
559  locale = (Locale) parameterValues.get(JRParameter.REPORT_LOCALE
);

where
  public static final String REPORT_LOCALE
 = "REPORT_LOCALE
";

Instead of using the provided params map, I also tried creating a fresh one and used it as a value for params instead, i.e.
  Map paramsMap = new HashMap();
Locale locale = RCU.getLocale(RCH.currentRequestAttributes().getRequest());
paramsMap.put("REPORT_LOCALE ", locale);
...
chain(controller:'jasper ',action:'index',model:[data:MODEL_DATA],params:paramsMap);

But this did not change anything.

To me it seems, the locale is somehow converted in its String representation. I guess it is some Groovy automatism that comes into play here.
So the question is where is this likely to happen and how to prevent it? Any ideas?

Thanks
fatzopilot

May 16, 2010; 10:53am

Re: Groovy Parameter Maps / Passing a locale to JasperReport

Reply Threaded More More options
Reply to author
Print post
Permalink
 
 
Click to star this item
Some javascript/style in this post has been disabled ( why? )

You can put objects in session/request/application scope because those are serverside Maps. But request parameters go into the querystring or post parameters, so they're sent as strings. When you add a non-string to the params it's added as its toString() value which you don't want. If you want to send the locale as a parameter your best bet is to send the locale language, country and variant and re-create it on the other side.

 

Burt

 

On May 16, 2010 at 2:43 PM fatzopilot < [hidden email] > wrote:

>
> Hi,
>
> I am using the jasperreports plugin and would like to pass the locale
> parameter to the reporting engine. There is a controller (jasper
> controller) for generating reports which is called (by chaining) from
> another controller that assembles the data (MODEL_DATA). There is also a
> params map that holds additional parameters. The controller looks as
> follows:
>
>
> import org.springframework.web.context.request.RequestContextHolder as RCH
> import org.springframework.web.servlet.support.RequestContextUtils as RCU;
> ...
> def report = {
>   Locale locale =
> RCU.getLocale(RCH.currentRequestAttributes().getRequest());
>   params.put("REPORT_LOCALE ", locale);
>   ...

> chain(controller:'jasper ',action:'index',model:[data:MODEL_DATA],params:params);
> }
>
> The important thing here is that the locale is actually instanceof
> java.util.Locale when it is put in the map.
> However, later on I get a
>
> java.lang.ClassCastException: java.lang.String cannot be cast to
> java.util.Locale
>         at
> net.sf.jasperreports .engine.fill.JRFillDataset.setParameterValues(JRFillDataset.java:559)
>
> The corresponding line reads
>
> 559  locale = (Locale) parameterValues.get(JRParameter.REPORT_LOCALE );
>
> where
>
>   public static final String REPORT_LOCALE = "REPORT_LOCALE ";
>
> Instead of using the provided params map, I also tried creating a fresh one
> and used it as a value for params instead, i.e.
>
>   Map paramsMap = new HashMap();
>   Locale locale =
> RCU.getLocale(RCH.currentRequestAttributes().getRequest());
>   paramsMap.put("REPORT_LOCALE ", locale);
>   ...

> chain(controller:'jasper ',action:'index',model:[data:MODEL_DATA],params:paramsMap);
>
> But this did not change anything.
>
> To me it seems, the locale is somehow converted in its String
> representation. I guess it is some Groovy automatism that comes into play
> here.
> So the question is where is this likely to happen and how to prevent it? Any
> ideas?
>
> Thanks
> fatzopilot
>
>
> --
> View this message in context: http://grails.1312388.n4.nabble.com/Groovy-Parameter-Maps-Passing-a-locale-to-JasperReport -tp2218569p2218569.html
> Sent from the Grails - user mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值