1 Reply Latest reply on Jan 13, 2010 1:17 PM by Leo van den berg

    Injecting messages resource bundle in backing bean

    Anil Erukala Newbie
      I am using seam 2.1.2GA. I have two messages.properties in my war file. One messages.properties we are inheriting from common project and another one is messages specific to my project. My faces-config.xml looks like this.

      `<?xml version="1.0" encoding="UTF-8"?>
      <faces-config version="1.2" xmlns="http://java.sun.com/xml/ns/javaee"
           xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">

           <!-- Facelets support -->

      In my backing bean I am injecting the appMessages resource bundle like this.

      `public class BackingBean {

      private Map<String, String> appMessages;

      public String myMethod(String messageKey) {
          String messageValue = appMessages(messageKey);

      Message key values are dynamic. That is why I have to inject the complete message resource bundle in my backing bean.
      But it is throwing an error saying that appMessages requires non-null value. It looks like it is not creating the appMessages seam component. Even when I modify @In to @In(create=true) or @In(required=false), it is not working.

      In seam reference manual, it is specified that we can inject messages in backing bean using `@In private Map<String, String> messages;`. Please provide some suggestions how to inject messages resource bundle in the above scenario.

        • 1. Re: Injecting messages resource bundle in backing bean
          Leo van den berg Master


          you should tell Seam that is should include your own bundle to its default.

          The most simple one is using the name

          message.properties and its language specific message_XX.prioprties

          and place it in the class path. The other one is adding let Seam handle the stuff. The defined resources are normally added to the default set by Seam and there is also the option to add a specific bundle by configuring it in componenst.xml.

          In your case using the standard Seam definition should work.