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

  • MessageSource

    Hi,

    Is it possible to use the following in the properties file for messageSource.

    sentence=My name is ${name}
    name=Bob

    The return value of messageSource.getMessage("sentence", null, null) would be:

    My name is Bob.

    I have tried using '${<code>}' and '{<code>}' but it is not working. Does anybody knows the syntax??

    cheers

  • #2
    Code:
    ResourceBundle.getBundle("messagesfile").getString("sentence");
    But I'm not sure that you can use ${code} in messageSource, I think it's only for JSP pages.

    Comment


    • #3
      I use struts2, springFramework 2.5.4. In actionExample.java class, the MessageSource always return NULL?



      In bean.xml:
      =====================================
      <bean id="messageSource" class="org.springframework.context.support.Resourc eBundleMessageSource">
      <property name="basename" value="application.properties" />
      </bean>

      <bean id="msgE" class="actionExample">
      <property name="msg" ref="messageSource" />
      </bean>


      In actionExample.java
      ===================
      public class actionExample extends ActionSupport
      {
      private MessageSource msg ;

      /**
      * @param msg The msg to set.
      */
      public void setMsg(MessageSource msg) {
      this.msg = msg;
      }



      public String execute() throws Exception
      {
      String str_msg = this.msg.getMessage("argument.required",
      new Object[] {"UserDao"}, "Required", null);

      /* ? this.msg return NULL */
      return success;
      }

      Could someone help, why the action class returns NULL MessageSource but not the instance defined in the bean.xml file?

      Comment

      Working...
      X