PDA

View Full Version : programatically looking up a i18n value from messageSource


sjivan
Sep 23rd, 2004, 02:29 PM
Is there a way to programatically lookup an i18n key from a configured messageSource? I'm working with some tags that are not EL aware and I need to pass in a label value after doing to i18n lookup.

Thanks,
Sanjiv

sjivan
Sep 24th, 2004, 10:10 AM
I figured out how to do this. Incase anyone else is interested, here's how I did it.

Basically add the bean property 'requestContextAttribute' on the InternalResourceViewResolver as below. 'requestContextAttribute' is of type org.springframework.web.servlet.support.RequestCon text and is made available as a request attribute ("rc", in this case) to the view and has convenience methods to look up messages from the configured messageSource.

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResou rceViewResolver">
<property name="viewClass"> <value>org.springframework.web.servlet.view.JstlView</value>
</property>
<property name="requestContextAttribute"><value>rc</value></property>
<property name="prefix">
<value>/jsp/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>