grails 是否支持使用“forEach”?来自 gsp 页面中的 JSTL 核心标签库?

发布于 2024-11-25 06:44:33 字数 826 浏览 6 评论 0原文

我在使用 grails 编写 gsp 页面时遇到问题。该页面可以与 JSTL 核心标签库中的其他标签(例如 c:if、c:when)配合使用。但是当我使用 c:forEach 进行循环时,我无法让它工作。以下是代码片段:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
......
<c:forEach var="foo" items="${fooList}" varStatus="counter">
    ${counter.count}, ${foo}
</c:forEach>

Grails 的错误表明隐式对象计数器为空。

Error 500: null
Servlet: 
URI: 
Exception Message: Cannot get property 'count' on null object 
Caused by: Error evaluating expression [counter.count] on line [16]: Cannot get property 'count' on null object

从Grails文档来看,据说支持JSP标签。

==>> “http://grails.org/doc/latest/guide/6.%20The%20Web%20Layer.html#6.3.6 使用 JSP 标签库”

但我就是无法让 c:forEach 工作,它工作得很好jsp 页面而不是带有 gsp 后缀。

Grails 版本:1.37 JDK:1.6.0_22

I had the problem in writing the gsp page using grails. The page works fine with other tags from JSTL core taglib, such as c:if, c:when. But I could not get it work when I was using c:forEach for looping. Following are the code snippets:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
......
<c:forEach var="foo" items="${fooList}" varStatus="counter">
    ${counter.count}, ${foo}
</c:forEach>

The errors from Grails shows that the implicit object counter is null.

Error 500: null
Servlet: 
URI: 
Exception Message: Cannot get property 'count' on null object 
Caused by: Error evaluating expression [counter.count] on line [16]: Cannot get property 'count' on null object

From the Grails documentation, it is said that JSP tags are supported.

==>> "http://grails.org/doc/latest/guide/6.%20The%20Web%20Layer.html#6.3.6 Using JSP Tag Libraries"

But I just could not get c:forEach to work, which works fine as a jsp page instead of having a gsp suffix.

Grails Version: 1.37
JDK: 1.6.0_22

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

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

发布评论

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

评论(2

前事休说 2024-12-02 06:44:33

最好对以下各项使用标准 GSP:

<g:each var="foo" in="${fooList}" status="counter">
    ${counter.count}, ${foo}
</g:each>

It's much better to use standard GSP's for each:

<g:each var="foo" in="${fooList}" status="counter">
    ${counter.count}, ${foo}
</g:each>
醉生梦死 2024-12-02 06:44:33

试试这个:

<g:each var="foo" in="${fooList}" status="counter">
    ${counter}, ${foo}
</g:each>

我遇到了同样的问题......
然后我发现是 ${counter} 而不是 ${counter.count} 来显示商品编号。

Try this instead:

<g:each var="foo" in="${fooList}" status="counter">
    ${counter}, ${foo}
</g:each>

I was having the same problem...
Then I figured out that it was ${counter} instead of ${counter.count} to get the item number to show up.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文