双重嵌套 EL 变量?

发布于 2024-12-07 02:50:30 字数 873 浏览 4 评论 0原文

我使用 Spring MVC 作为我的控制器,JSP 是我的表示层。

在我的 Spring 控制器中,我有:

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

所以现在在我的 JSP 中,我可以访问

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

这一切都很好。但为了使我的代码可扩展,我想将变量名 issuesfunctions 存储在数据库内,然后可以通过 issues 上的属性来访问它们。 code>configs 正在循环的对象。所以我想要的结果如下:

<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} 将保存 issuesfunctions在这个例子中。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你又不是我 2024-12-14 02:50:30

你很接近了。您只需删除嵌套的 ${} 因为这是无效的语法。

<myTagLib:select values="${requestScope[cfg.selectorName]}" />

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

<myTagLib:select values="${requestScope[cfg.selectorName]}" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文