Announcement Announcement Module
Collapse
No announcement yet.
MessageSource and args Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • MessageSource and args

    I'm having a problem with some simple code that uses values in a properties file.
    This is from a web service that was recently moved from Metro to CXF. It's also now running on Weblogic instead of Glassfish.

    When I run code similar to the simple example below, I get the following output:
    field.age is a required value.
    The desired output is this:
    Age is a required value.
    Should I expect this to work? I think so, because it used to work (Metro/Glassfish). I don't know what I could have done to mess this up. I'm also puzzled why it kind of works. I mean, and here's the real question, why won't Spring resolve the argument(s)?

    Spring version is 2.5.6.SEC01.

    messages.properties file
    Code:
    required.message={0} is a required value.
    field.age=Age
    sample code
    Code:
    @Autowired
    MessageSource messageSource;
    
    public String test() {
        String messageKey = "required.message";
        String [] args = {"field.age"};
        return messageSource.getMessage(messageKey, args, null);
    }
    cxf-config.xml
    Code:
        <!-- Messages -->
        <bean id ="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
            <property name="basenames">
                <list>
                    <value>messages</value>
                </list>
            </property>
        </bean>

  • #2
    Aww nuts.

    This hasn't ever worked - forget I said anything.

    Comment


    • #3
      BTW the behaviour showed is normal. Arg strings are substituted literally, so to make it work as you intended you should change it to:

      Code:
      @Autowired
      MessageSource messageSource;
      
      public String test() {
          String messageKey = "required.message";
          String [] args = {messageSource.getMessage("field.age")};
          return messageSource.getMessage(messageKey, args, null);
      }

      Comment

      Working...
      X