Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Controller that simulates spring:message tag?

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?

like image 291
Hurda Avatar asked Dec 17 '22 22:12

Hurda


1 Answers

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);
    }
}
like image 118
Hurda Avatar answered Jan 04 '23 00:01

Hurda