开发者

Does grails support using "forEach" from JSTL core taglib in gsp page?

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 i开发者_JAVA百科s 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


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

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜