-
1. Re: Inconsistent behaviour of calling messages from code
wilczarz.wilczarz.gmail.com Sep 10, 2009 11:03 AM (in response to wachtda.scsi.gmx.ch)I have run into the same problem a while ago. The problem is that when mailAction is instantiated by Seam, bijection takes place and the bundle is loaded properly. But after server restart, this is just a plain ejb instantiated by timer service (in your case - Quartz). There's no use from @In outside Seam container.
My solution is: when I need to access the bundle from a component that might live outside Seam context, I use this code:
@Name( "stringUtils" ) @AutoCreate public class StringUtils { ... public String getBundleMsgForEjb( String bundleKey, Object... arguments ) { if( bundleKey == null ) { return null; } try { ResourceBundle resourceBundle = ResourceBundle.getBundle( "messages" ); String bundleValue = resourceBundle.getString( bundleKey ); if ( bundleValue != null && arguments.length > 0 ) { String rawMsg = bundleValue.replaceAll( "'", "''" ); return MessageFormat.format( rawMsg, arguments ); } else { return bundleValue; } } catch ( MissingResourceException e ) { log.info( "Can't find bundle or bundle value for key: #0. Returning the key.", bundleKey ); } return bundleKey; }
Please note that you need to place messages_XX.properties directly in jar file, so you probably want to modify your ant script.
Good luck ;-)
Tom -
2. Re: Inconsistent behaviour of calling messages from code
wachtda.scsi.gmx.ch Sep 10, 2009 1:25 PM (in response to wachtda.scsi.gmx.ch)Hi Tom
Thank you for your quick answer.
I forget to mention, that i have also a view in the seam context, from which i can start the mailAction manually.
If I start the mailAction manually i got the same problems...I don't get the clue because If I login, seam is started and also the messages, isn't it?
Thanks for helping -
3. Re: Inconsistent behaviour of calling messages from code
wachtda.scsi.gmx.ch Sep 10, 2009 1:42 PM (in response to wachtda.scsi.gmx.ch)I just tested as you sugested!
- If I make a server restart, login into my seam app and call the mailAction, the messages doesn't get fetched!
- If I make a restart of the application (touch application.ear), login into my seam app, the messages get fetched as they should!
This is the behaviour explained by Tom! Thank you!
Perhaps I am to stupid, but I don't understand your explication...Why seam isn't started properly, if I make a server restart and login in my seam application?