Reputation: 357
In the resource bundle properties file I have following text
system.invalidID = This accountID $ is not valid for current session.
I want to replace dynamically $(this will be the actual ID at runtime) from the above resource text in my JSP and java Class.
Can we do this in JSP and java?
Upvotes: 0
Views: 1151
Reputation: 269637
You can parameterize messages using JSTL's <fmt:message>
and <fmt:param>
tags together.
The basename
attribute below refers to the base name of your ResourceBundle
property files, which must be accessible on the webapp's classpath. Putting everything together looks like this:
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<fmt:setBundle basename="com.y.app.Messages" var="bundle" />
<fmt:message bundle="${bundle}" key="system.invalidID">
<fmt:param value="${attemptedID}" />
</fmt:message>
Upvotes: 3
Reputation: 44813
You could try the JSTL Core <fmt:bundle> Tag
see http://www.tutorialspoint.com/jsp/jstl_format_bundle_tag.htm
Upvotes: 1
Reputation: 240860
You can actually create a simple class with a method something like
public class ResourceBundleHelper{
public String resolveMessage(String key){
//code
}
}
and then create instance of this class and put it to ServletContext
and then from jsp el
${resourceBundleHelper.resolveMessage(YOUR_VARIABLE)}
Upvotes: 0