You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Tom Hjellming <th...@gmail.com> on 2012/03/01 00:05:31 UTC

Re: Struts2 w/freemarker and internationalization

Thanks Josep - that works.

I thought the ${} notation was equivalent to the <@s> form - but I guess 
not.

thanks,
Tom

On 2/29/12 12:16 PM, Josep GarcĂ­a wrote:
> Try with:
>
> <p><@s.text name="welcome.message"/></p>
>
> Cheers,
> Josep
>
>
> 2012/2/29 Tom Hjellming<th...@gmail.com>
>
>> I'm trying to internationalize a simple Struts2-based webapp that uses
>> Freemarker as the view technology.  The usage of freemarker templating
>> pulling values from the Action object is working fine.
>>
>> But when I try to leverage Struts2's TextProvider capability via
>> getText(), it doesn't work.
>>
>> My action extends ActionSupport which implements the TextProvider
>> interface.
>>
>> My freemarker template file contains this:
>>
>> <p>${getText('welcome.message'**)}</p>
>>
>> My properties file is:  {MyActionName}.properties and located in same
>> directory as the java source.  It contains:
>>
>> welcome.message=The Welcome message goes here
>>
>> But I get the dreaded freemarker.core.**InvalidReferenceException:
>>   Expression getText is undefined.
>>
>> To test that the resource bundle can be located, I inserted code in my
>> Action's execute():
>>         String res;
>>         try
>>         {
>>             res = getText("welcome.message", "default welcome msg from
>> execute() method");
>>         }
>>         catch (Throwable e)
>>         {
>>             res = null;
>>         }
>>
>> With the debugger, I see the res is being set to 'The Welcome message goes
>> here' -- which tells me the ResourceBundle is working inside TextProvider.
>>
>> So it seems the issue is Freemarker not accessing the TextProvider
>> interface.
>>
>> Other things I've tried:
>> - ${text('welcome.message')} -- same result
>> - having my action implement TemplateMethodModel per this link:
>> http://weblog.masukomi.org/**2009/03/12/localization-for-**
>> struts-freemarker-users/<http://weblog.masukomi.org/2009/03/12/localization-for-struts-freemarker-users/>  but that didn't work either.
>>
>> Can anyone provide any hints for how to get this very basic thing working?
>>
>> thanks,
>> Tom
>>
>>
>> ------------------------------**------------------------------**---------
>> To unsubscribe, e-mail: user-unsubscribe@struts.**apache.org<us...@struts.apache.org>
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org