加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Groovy Parameter Maps / Passing a locale to JasperReport

发布时间:2020-12-14 17:04:51 所属栏目:大数据 来源:网络整理
导读:? 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 as

?

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 ",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

read-only

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 ',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 ",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
>
>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读