Doubly nested EL variables?
Asked Answered
A

1

5

I'm using Spring MVC for my controller, and JSPs are my presentation layer.

Inside my Spring controller, I have:

model.put("issues", dataManager.getIssues());
model.put("functions", dataManager.getFunctions());

So now inside my JSP, I have access to

${requestScope['issues']}
${requestScope['functions']}

That's all well and good. But in order for my code to be extensible, I would like to store the variable name issues and functions inside the database, which will then be accessible through a property on a configs object that's being looped over. So what I'd like to end up with is something like the following:

<c:forEach items="${configs}" var="cfg">
    <c:if test="${cfg.configType == 'select'}">
        <th>${cfg.header}</th>
        <td><myTagLib:select values="${requestScope['${cfg.selectorName}']}" /></td>
    </c:if>
</c:forEach>

Where ${cfg.selectorName} will hold either issues or functions in this example.

Amieeamiel answered 27/9, 2011 at 1:32 Comment(0)
L
7

You're close. You only need to remove the nested ${} since that's invalid syntax.

<myTagLib:select values="${requestScope[cfg.selectorName]}" />
Loser answered 27/9, 2011 at 1:36 Comment(2)
@BalusC, I'm doing like <c:set var="fullPath" value="${commandName}.courseList"/> <c:forEach items="${requestScope[fullPath}"> <!-- ... --> </c:forEach>. But I'm not able to get item list this way. please help.Arnettearney
items='${request.getAttribute(fullPath)}' is also not solving my purpose.Arnettearney

© 2022 - 2024 — McMap. All rights reserved.