views:

21

answers:

2

I'm designing help/hint system for my webpage, I'd like to incoroporate jQuery based contextual help.

My idea is that I would post request on event and show given repsonse in special div or so.

I would like to get similiar behaviour as <spring:message> tag, post message code and get String representation on localized message. It would be great if it would use same resources.

Is there a way to call this tag from Controller? (there is Java code behind this tag) Or what's best way to mimick this tag controller-side?

+1  A: 

Use ResourceBundleMessageSource to declare the messages and then autowire/inject to your controller.

<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"            p:basename="messages"/>

alternatively you can use util: properties to load a properties file.

<util:properties id="jdbcConfiguration" location="classpath:com/foo/jdbc-production.properties"/>

then access this resource in your controller using the id.

Teja Kantamneni
Didn't occure to me, that using same message source will be so easy - THANKS
Hurda
A: 

With the help of Teja Kantamneni I come with this Controller


@Controller
public class HelpController {
    protected Log log = LogFactory.getLog(getClass());

    @Autowired  
    private MessageSource messageSource;

    @RequestMapping(value = "ajax/gethelp")
    public @ResponseBody String handleGetHelp(Locale loc, String code) {
        return messageSource.getMessage(code, null, loc);
    }
}
Hurda