Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ResourceBundleMessageSource resolving error

Tags:

java

spring

jsp

I have a JSP-Tagfile which renders the html-header and defines my Javascript/Stylesheet resources.

<%@ tag language="java" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<html>
<head>
    <link rel="stylesheet" type="text/css" href="<spring:theme code="main.css"/>"/>
    <script type="text/javascript" src="<spring:theme code="default.js"/>"></script>
...

</html>

Now i wan't to load a i18n messages for the javascript stuff.

var button_ok='<spring:message code="js.button.ok" javaScriptEscape="true"/>';

When i use this inside the tag-file it works as supposed and resolves the messages, even if there is only a default messages.properties (fallback).

But if i load the messages with an external javascript file lang.js.jsp it only tries to resolve the message code against the properties for the current language and the fallback to the default one is not working.

like image 737
RicoZ Avatar asked Jun 28 '26 03:06

RicoZ


1 Answers

If the message should be resolved inside the tag, the ApplicationContext defined within the DispatcherServlet is used. Otherwise the ApplicationContext from the ContextLoaderListener is used (root application context).

To solve the problem i moved the ResourceBundleMessageSource into the configuration which is loaded by the ContextLoaderListener.

like image 165
RicoZ Avatar answered Jun 30 '26 18:06

RicoZ



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!