aspose file tools*
The moose likes Spring and the fly likes MessageSourceAccessor bundle of messages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "MessageSourceAccessor bundle of messages" Watch "MessageSourceAccessor bundle of messages" New topic
Author

MessageSourceAccessor bundle of messages

Luis Parente
Ranch Hand

Joined: Jan 17, 2012
Posts: 39
Hi all,

I have a problem with my resource bundle. For retrieve my messages I do the following:



and I use it in an exception like that:



In the method getMessage I have defined a string default

In mode debug I can see that username(args to substitute in string ) is not null and in my security_fr_FR.properties the value of code DigestAuthenticationFilter.usernameNotFound it's ok.



But, when the exception is throw, in my jsp the text in not correctly written: , the args is not replace the argument.

If I spell a wrong code String, the default string is used and the message is correctly written in my JSP. if username equals to TOTO.


Any idea please?


Thanks in advance.


Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1666
    
    7

Make sure the context your are defining your SpringSecurityMessageSource is correct. Also I don't see you defining a locale. Try passing the correct locale into getMessage. You can also try setting the locale or verifying it is correct in the LocaleContextHolder.



[How To Ask Questions][Read before you PM me]
Luis Parente
Ranch Hand

Joined: Jan 17, 2012
Posts: 39
Thanks for your response, but about the local, I think the default local is used or I make a mistake?
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1666
    
    7

It uses the locale you pass in. If you do not provide a locale it will use the one on the LocaleContextHolder.
Luis Parente
Ranch Hand

Joined: Jan 17, 2012
Posts: 39
Hi,

I have modified the getMessage

catch(EmptyResultDataAccessException msgErr){
throw new BadCredentialsException(messages.getMessage("DigestAuthenticationFilter.usernameNotFound",
new Object[]{username}, "Utilisateur {0} non paramétré en base", LocaleContextHolder.getLocale()));


and LocaleContextHolder.getLocale() is equal 'fr_FR', but the problem continue.

Thanks in advance.
Bill Gorder
Bartender

Joined: Mar 07, 2010
Posts: 1666
    
    7

OK well you can revert back to what you had. I just wanted to make sure that it was indeed defined correctly on the LocaleContextHolder. The MessageSourceAccessor class will pull it off of there for you so you don't need to pass it in.

I would go back to looking at context scoping. Perhaps your messagesource in the context is not available like you think it is. Try to call a different get message use this one.



With this constructor you are not providing a default message so it will throw a NoSuchMessageException if it is not found. If this happens you know there is an issue with being able to properly find it.
 
Don't get me started about those stupid light bulbs.
 
subject: MessageSourceAccessor bundle of messages