JSTL Core fmt:message Tag Dynamic message using bundle/properties file

jakarta-ee, java, jsp, jstl, web-applications

Solution

You can define properties like

MQ2009 = Mq timeout happened for {0}

and then

<fmt:message key="MQ2009" var="val" >
   <fmt:param value="${valueComingFromSomeParameter}"/>
</fmt:message>

and then

<c:out value="${val}"/>

Problem

I understand the usage of standard `fmt:message` Tag i.e we define something like this in the JSP: ``` <fmt:setBundle basename="ResourceBundles.ValidationErrorMessages" var="errorMessages" /> <fmt:message key="${error.value}" bundle="${errorMessages}" /> ``` Suppose error.Value = "MQ2009" My properties file named "ValidationErrorMessages" has following entry ``` MQ2009 = MQ time out ``` Now my requirement is to have something like ``` MQ2009 = Mq timeout happened for message {messagename}. ``` Can I define the `messagename` variable dynamically? I.e at runtime, `messagename` will be available in request scope and it should be substituted in the properties file. How can I do this? Do I need a custom tag or does Java EE provides this feature which I am not aware off?

Original source