Re: methods with parameters
Daniel Dekany <[email protected]>
| Newsgroups | gmane.comp.web.freemarker.user |
|---|---|
| Message-ID | <[email protected]> |
Monday, September 13, 2010, 10:54:05 AM, Flower, Martin wrote:
> Hi,
>
> org.springframework.context.MessageSource
>
> String getMessage(String code, Object[] args, Locale locale) throws NoSuchMessageException;
>
> args is used for example in
>
> greeting=Hello {0}
>
> In velocity I have the current code for that as
>
> #set ($xx = $changed.getTitle() + " " +
> $changed.getFirstName() + " " + $changed.getLastName())
> #set ($salutation = [$xx])
> ${messageSource.getMessage("greeting", $salutation.toArray(), $locale)}
>
> Bit of fiddling with Velocity's List, compared to the method's Object[]
As far as the MessageSource doesn't also extend j.u.Map, this should
work in similar manner in FM as well (except that you don't need the
toArray call).
>
>
> -----Original Message-----
> From: Daniel Dekany [mailto:[email protected]]
> Sent: Monday, September 13, 2010 10:48 AM
> To: Flower, Martin
> Cc: [email protected]
> Subject: Re: [FreeMarker-user] methods with parameters
>
> Monday, September 13, 2010, 9:00:57 AM, Flower, Martin wrote:
>
>> Hi - in Velocity I do the following
>>
>> ${messageSource.getMessage("update.email.subject", null, $locale)}
>>
>> I have looked up and down the freemarker manuals - I know it must
>> be staring me in the face, but I can't find an example of how to do
>> this in Freemarker (which I would prefer). I know I can call
>> methods without parameters, for example ${locale.getDisplayLanguage()}.
>>
>> Any pointers ?
>
> What's "messageSource"? Because it's not a ResourceBundle as that
> doesn't have "getMessage" method.
>
> You might find something useful here:
> http://freemarker.org/docs/pgui_misc_beanwrapper.html
> Look for the occurrences of ResourceBundle on this page. AFAIR it
> should automatically select the messages with the locale that
> corresponds to the "locale" setting of FreeMarker.
>
> If you need something more special, then you can always write a
> TemplateMethodEx implementation and put it into the data-model or
> create it in an #import-ed/#include-ed library with
> "com.example.MyMessageSource"?new().
>
--
Best regards,
Daniel Dekany
------------------------------------------------------------------------------
Start uncovering the many advantages of virtual appliances
and start using them to simplify application deployment and
accelerate your shift to cloud computing
http://p.sf.net/sfu/novell-sfdev2dev