The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

walrus (14) [Avatar] Offline
#1
After following your instructions on pg. 46 (not using a Fragment at this time but just the messages.properties file), I receive the following message . . .

java.util.MissingResourceException: Can't find bundle for base name fancyfoods.web.messages, locale en_US
at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:1539)
at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:127smilie
at java.util.ResourceBundle.getBundle(ResourceBundle.java:805)
at fancyfoods.web.SayHello.doGet(SayHello.java:19)
. . .

Looks like it is looking for a message that is tagged (in some way) with en_US.
I see that the code asks for the locale from the browser, but I don't see where it get the message based on the locale.

Was something left out in the instructions?


Thanks.
holly.cummins (16) [Avatar] Offline
#2
Re: Issue Under Fragments - Ch. 2
I'm sorry to hear you're hitting problems. I wonder whether what you're seeing is a build issue.

It should be that as long as you have a file called messages.properties, your messages will be found. If you're in the en_US locale, the ResourceBundle will look first for a file called messages_en_US.properties. If it can't find that, it will look for messages_en.properties, and if it can't find that either, it will look for messages.properties. So in principle, no matter what locale you're using, messages will be found.

The first thing I'd suggest checking is the contents of your fancyfoods.web bundle; you should have a file in the fancyfoods/web folder, called messages.properties. Depending how you're packaging up the bundle, the build tools could have left out the properties files. Certainly from your stack trace it looks like it can't find the default messages.properties file.

The lines which triy to get the message from the messages.properties file are these ones:

String bundleName = "fancyfoods.web.messages";
ResourceBundle resources = ResourceBundle.getBundle(bundleName, locale);
String greeting = resources.getString("SayHello.hello");

(Those bundles are normal Java resource bundles, not OSGi bundles, which does rather muddy things.)

Hope this helps,
Holly
holly.cummins (16) [Avatar] Offline
#3
Re: Issue Under Fragments - Ch. 2
Hi again,

I've just done a bit more digging into this, and I think my diagnosis that a build problem is causing the messages.properties file to be missing from your fancyfoods.web bundle is probably correct. However, the problem is our fault (if you're using the poms provided with the source download)! A mistake in where the messages.properties file gets laid out in the source zip means it doesn't get included in the built jar. It should be in src/main/resources, but it's in src/main/java. I'll make sure that's fixed in the next refresh of the source zip.

Thanks for reporting the issue.

Holly
walrus (14) [Avatar] Offline
#4
Re: Issue Under Fragments - Ch. 2
Thank you for checking into this further and updating.