Results 1 to 3 of 3

Thread: Access messages using code in java files

Hybrid View

  1. #1

    Default Access messages using code in java files

    How do I access messages and labels that are defined in resou

    I have the following defined in servlet.xml
    Code:
    <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
    		<property name="basenames">
    				<list>
    						<value>myapp</value>
    						<value>myapp-messages</value>
    				</list>
    		</property>
    </bean>
    I have two property files. One for labels(myapp.properties) and one for error messages (myapp-messages.properties).
    Code:
    myapp-messages.properties: 
    failedInSaveMessage=Failed while saving the customer record.

    I know how to access the messages that are defined in these property files from jsp.
    for eg:
    Code:
    <c:set var="errMessage"><spring:message code='failedInSaveMessage'/></c:set>
    <c:out value="${errMessage}"/>
    I want to access these messages from java file, so that I can prepare my errors obj after fetching
    data from DB. I am not using validator interface.

    How do I access msg text that is defined in resource files using msg code in java files?

    Basically I need something like "spring:message code='failedInSaveMessage'"

  2. #2
    Join Date
    May 2008
    Location
    Central Florida, U.S.A.
    Posts
    36

    Default

    The following can be used off the "messageSource", if you inject it into the class you want to read the message text:

    Code:
    messageSource.getMessage(String code, Object[] args, Locale locale)
    You can pass in null for the second argument. It is for replacements in the message text. Locale can be retrieved from the HttpServletRequest.

  3. #3

    Default

    Thank you very much!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •