双嵌套EL变量? [英] Doubly nested EL variables?
问题描述
我正在使用Spring MVC作为控制器,而JSP是我的表示层.
I'm using Spring MVC for my controller, and JSPs are my presentation layer.
在我的Spring控制器中,我有:
Inside my Spring controller, I have:
model.put("issues", dataManager.getIssues());
model.put("functions", dataManager.getFunctions());
所以现在在我的JSP中,我可以访问
So now inside my JSP, I have access to
${requestScope['issues']}
${requestScope['functions']}
一切都很好.但是为了使我的代码可扩展,我想将变量名称issues
和functions
存储在数据库中,然后可以通过正在循环的configs
对象上的属性对其进行访问.因此,我最终希望得到的是以下内容:
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>
在此示例中,${cfg.selectorName}
将容纳issues
或functions
.
Where ${cfg.selectorName}
will hold either issues
or functions
in this example.
推荐答案
您已经关闭.您只需删除嵌套的${}
,因为这是无效的语法.
You're close. You only need to remove the nested ${}
since that's invalid syntax.
<myTagLib:select values="${requestScope[cfg.selectorName]}" />
这篇关于双嵌套EL变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!