Processing Dynamic Variable in JSTL

I have problem getting the result of a JSTL variable dynamically. Here is the scenario.
I have defined messages for some status values as follows in the page.

<c:set var=“messagestatus1a” value=“Less than 30 days with ME” /> <c:set var=“messagestatus1b” value=“30 days or more with ME” /> <c:set var=“messagestatus2a” value=“Less than 30 days with JPM”/> <c:set var=“messagestatus2b” value=“30 days or more with JPM” />

I get a status value from the database (such as status1a, status1b, status2a, status2b) and I am concatenating with ‘message’ so that I can frame the appropriate variable name.

<c:forEach var=“suggestionsLoop” items=“${suggestionQuery.rows}”>
<c:set var=“msgDesc” value=“message${suggestionsLoop.status}” />
<!-- Now, ‘msgDesc’ variable has a value like ‘messagestatus1a’ or ‘messagestatus1b’ etc.,
I would like to reprocess the value from msgDesc to diaplay the appropriate message.
If I try ${${msgDesc}} obviously I am getting error. Any ideas how to accomplish this ?
–>
</c:forEach>

Thanks,
vmrao

Don’t think it’s possible. Try to use c:choose or put your message in a map.

have you tried

<c:set var=“msgDesc” value="${‘message’+suggestionsLoop.status} "/>

I don’t remember if this is allowed in EL but it might work.

As a last option you can always use <% %> and use the pageContext object.

<c:forEach var=“suggestionsLoop” items=“${suggestionQuery.rows}”>

<c:choose>

<c:when test =“${suggestionsLoop.status ==‘messagestatus1a’}
<c:out value =”${messagestatus1a}"/>
</c:when>

<c:when test =“${suggestionsLoop.status ==‘messagestatus1b’}
<c:out value =”${messagestatus1b}"/>
</c:when>

etc.

</c:choose>

Hope that helps

Thanks for your replies.

The following worked as per JSP Spec.

<c:set var=“statusMsg” value=“${pageScope[msgDesc]}” />

${statusMsg}

Nice, didn’t think of that. Thanks for coming back with a good solution.

thought about using:

<c:set var="msgStatus">${DBresult}message</c:set>

and then accessing the variable when needed?

at worst, you could just include a JSPF (fragment) that doesnt have XML bounds set on it. Would allow you construct the dynamic variable without a problem then.