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