yes works great:

       ResourceBundle messages =
           ResourceBundle.getBundle(Constants.BUNDLE_KEY,
           LocaleContextHolder.getLocale());
           logger.debug(messages.getString("company.url"));

and make sure you import:
import org.appfuse.Constants;

i will make a myBaseObject with a getText method in it.. than it will be nice and equal to my action ;)

tibi

Matt Raible wrote:
On 4/26/07, Jonathan Tse <[EMAIL PROTECTED]> wrote:
I see your point.

And I agree that Model can reach MessageSourceAccessor.

Currently in Spring MVC, i18n is not supported very well too (or i miss
something?).
I duplicated BaseFormController to a BaseController so that all
controllers which implements
org.springframework.web.servlet.mvc.Controller are changed to  extend
this class.

So, is there anyway that we can provide a MessageSourceAcceessor to
BaseObject?

Why not use a regular ol' ResourceBundle.  You should be able to do
this in your model object:

ResourceBundle messages =
ResourceBundle.getBundle(Constants.BUNDLE_KEY,
LocaleContextHolder.getLocale());

The user's locale is stored in a ThreadLocale from the LocaleFilter.
I don't know how thread-safe this is, but it should work.  Of course,
you might have to manipulate your DAO tests so
ApplicationResources.properties is on your classpath - but this should
work. I don't know how thread safe it is or how it'll work if you
transport your model objects as DTOs over web services.

Matt


Jonathan


tibi wrote:
> there are more situations where it could be handy to have i18n if you
> want to keep your jsp clean.
> like get fullname
>
> class user{
>
> string getFullname(){
> return super.getText("fullname",first, last);// en: matt raible - hu:
> raible, matt
> }
>
> }
>
> offcoure this could be done in the jsp but i like java in model and
> tags in jsp ;)
>
>
> tibi
>
>
>
> tibi wrote:
>> and the model can't be i18n?
>>
>> if i would put the i18n into the database that would be realy a lot
>> of overhead. than i rather do iets the strange why ;)
>>
>> tibi
>>
>> Matt Raible wrote:
>>> On 4/26/07, tibi <[EMAIL PROTECTED]> wrote:
>>>> why does the BaseObject not have a getText method?
>>>
>>> Because it's part of the model/dao layer.  You might want to use
>>> something like the following to 1i8n-ize your data tier.
>>>
>>> http://www.theserverside.com/tt/blogs/showblog.tss?id=HibernateInternational
>>>
>>>
>>> Matt
>>>
>>>>
>>>> tibi
>>>>
>>>> tibi wrote:
>>>> > mmm its business knowledge i like it to be in the model.
>>>> > and i like to simplify my jsp as much as possible.
>>>> > i could push my action into my model and use the getText method.
>>>> >
>>>> > a bit wierd but seems logical.
>>>> >
>>>> > there are more examples where a getText comes in handy. like if you
>>>> > want the date.format
>>>> >
>>>> > tibi
>>>> >
>>>> > Matt Raible wrote:
>>>> >> I would do some checking in your view - i.e. <c:if test="${empty
>>>> >> locations}"><fmt:message key="traveling.key"/></c:if>, otherwise
>>>> show
>>>> >> city.
>>>> >>
>>>> >> Matt
>>>> >>
>>>> >> On 4/26/07, tibi <[EMAIL PROTECTED]> wrote:
>>>> >>> pseudo code:
>>>> >>>
>>>> >>> class Event
>>>> >>>
>>>> >>> list locations
>>>> >>>
>>>> >>> String getSimpleLocation(){
>>>> >>> if(locations.size()==1){
>>>> >>> return location.get(0).getCity();
>>>> >>> }
>>>> >>> return 'traveling';
>>>> >>> }
>>>> >>>
>>>> >>> someting like this?
>>>> >>>
>>>> >>> tibi
>>>> >>>
>>>> >>>
>>>> >>> Matt Raible wrote:
>>>> >>> > I don't understand what you're trying to do - can you post code?
>>>> >>> >
>>>> >>> > On 4/26/07, tibi <[EMAIL PROTECTED]> wrote:
>>>> >>> >> i have an event with a  getSimpleLocation in it.
>>>> >>> >> my object can have multiple location
>>>> >>> >> if there is 1 location return the location
>>>> >>> >> if there are multple return 'traveling'
>>>> >>> >>
>>>> >>> >> tibi
>>>> >>> >>
>>>> >>> >> Matt Raible wrote:
>>>> >>> >> > How do you want to use i18n in your models?
>>>> >>> >> >
>>>> >>> >> > On 4/26/07, tibi <[EMAIL PROTECTED]> wrote:
>>>> >>> >> >> ok it works in actions but how can i use it in my models?
>>>> >>> >> >> should i pass my action into the moddel to use her getText
>>>> >>> method?
>>>> >>> >> >>
>>>> >>> >> >> tibi
>>>> >>> >> >>
>>>> >>> >> >> tibi wrote:
>>>> >>> >> >> > ahhh it must be the super.getText("") method ;)
>>>> >>> >> >> >
>>>> >>> >> >> > tibi
>>>> >>> >> >> >
>>>> >>> >> >> > tibi wrote:
>>>> >>> >> >> >> hi,
>>>> >>> >> >> >>
>>>> >>> >> >> >> i can't find an example of how to use i18n from within my
>>>> >>> actions.
>>>> >>> >> >> >> in struts it used to something like this:
>>>> >>> >> >> >> errors.add(ActionErrors.GLOBAL_ERROR, new
>>>> >>> >> >> >> ActionError("key.order.no.item"));
>>>> >>> >> >> >>
>>>> >>> >> >> >> but in struts2 this will not work.
>>>> >>> >> >> >>
>>>> >>> >> >> >> anyone?
>>>> >>> >> >> >>
>>>> >>> >> >> >> thanks
>>>> >>> >> >> >>
>>>> >>> >> >> >> tibi
>>>> >>> >> >> >>
>>>> >>> >> >> >>
>>>> >>> >>
>>>> >>>
>>>> ---------------------------------------------------------------------
>>>> >>> >> >> >> To unsubscribe, e-mail:
>>>> [EMAIL PROTECTED]
>>>> >>> >> >> >> For additional commands, e-mail:
>>>> >>> [EMAIL PROTECTED]
>>>> >>> >> >> >>
>>>> >>> >> >> >>
>>>> >>> >> >> >
>>>> >>> >> >> >
>>>> >>> >>
>>>> >>>
>>>> ---------------------------------------------------------------------
>>>> >>> >> >> > To unsubscribe, e-mail:
>>>> [EMAIL PROTECTED]
>>>> >>> >> >> > For additional commands, e-mail:
>>>> >>> [EMAIL PROTECTED]
>>>> >>> >> >> >
>>>> >>> >> >> >
>>>> >>> >> >>
>>>> >>> >> >>
>>>> >>>
>>>> ---------------------------------------------------------------------
>>>> >>> >> >> To unsubscribe, e-mail:
>>>> [EMAIL PROTECTED]
>>>> >>> >> >> For additional commands, e-mail:
>>>> [EMAIL PROTECTED]
>>>> >>> >> >>
>>>> >>> >> >>
>>>> >>> >> >
>>>> >>> >> >
>>>> >>> >>
>>>> >>> >>
>>>> >>>
>>>> --------------------------------------------------------------------- >>>> >>> >> To unsubscribe, e-mail: [EMAIL PROTECTED]
>>>> >>> >> For additional commands, e-mail:
>>>> [EMAIL PROTECTED]
>>>> >>> >>
>>>> >>> >>
>>>> >>> >
>>>> >>> >
>>>> >>>
>>>> >>>
>>>> ---------------------------------------------------------------------
>>>> >>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>>>> >>> For additional commands, e-mail: [EMAIL PROTECTED]
>>>> >>>
>>>> >>>
>>>> >>
>>>> >>
>>>> >
>>>> >
>>>> ---------------------------------------------------------------------
>>>> > To unsubscribe, e-mail: [EMAIL PROTECTED]
>>>> > For additional commands, e-mail: [EMAIL PROTECTED]
>>>> >
>>>> >
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>>>> For additional commands, e-mail: [EMAIL PROTECTED]
>>>>
>>>>
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to