Reputation: 690
I am setting the hardcoded messages for Ex: "Are you sure, you want to delete the message?" ,in the message.properties file.
Want to take this messages from the message.properties into javascript. Please suggest me ways to achive this.
For ex:
BootstrapDialog.show({
message: 'Are you sure you want to '+activeStatus+' this message ?',
title: 'Alert'
});
function handleAjaxError(xhr, textStatus, error) {
if (textStatus == 'timeout') {
alert('The server took too long to send the data.');
} else if (textStatus == "parsererror") {
alert("Ajax error occured.");
}
}
Upvotes: 2
Views: 4431
Reputation: 309
You could read resource properties(messages_en.properties)file from JSP/JSPF file like this
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<fmt:setLocale value="en"/>
<fmt:setBundle basename="messages"/>
<script type="text/javascript">
var activeStatus= '<fmt:message key="activeStatus"/>';
</script>
or using AJAX
Upvotes: 1
Reputation: 186
Write a service that reads all properites and writes Javascript code to its output file like.
Returned content should be like
var properties = { p1:'value1', ... };
and after that include this from your page with html script tag.
Upvotes: 0
Reputation: 2989
Have a look at the Spring theme tag :
Retrieves the theme message with the given code, or text if code isn't resolvable. The HTML escaping flag participates in a page-wide or application-wide setting (i.e. by HtmlEscapeTag or a "defaultHtmlEscape" context-param in web.xml).
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<spring:theme code="code.of.your.message" text="Alternative text"/>
Upvotes: 1
Reputation: 1292
Before your javascript is first initialized, you can make an ajax call to get i18n texts, and assign them to an javascript object. Later in your js code you can get text from it. Of course you need to have a backend controller to read texts from your message.properties files and gives response to your ajax request.
You need to load your javascripts in the callback of this ajax request, otherwise your text values would be undefined. (Because ajax takes some time).
Upvotes: 0