c:foreach 仅返回一个空值
我正在使用 JSF 2,并且出于某些目的需要 c:foreach。但无论我的列表有多大,c:foreach 只循环一次,返回空值。我尝试了一切,我什至将 c:foreach 隔离在单独的 .xhtml 中,但它仍然给出相同的结果。如果您需要一些代码,请询问,但我想让 c:foreach 至少在单独的 .xhtml 中工作,并且我认为它也可以在我的代码中工作。
I'm using JSF 2 and I need c:foreach in some purposes. But no matter how big my list is, c:foreach loops only once, returning empty value. I tried everything, I even isolated c:foreach in separate .xhtml, but it still gives same result. If you need some piece of code, please ask, but I would like to make c:foreach work at least in separate .xhtml, and I supose that than it will work in my code, too.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在网络浏览器中打开页面,右键单击并查看源代码。您在其中看到了普通的
标记,对吧?它根本没有被解析和执行?这是不对的。您需要确保已在 XML 命名空间中声明 JSTL 核心标记库,以便 Facelets 能够解析和执行它。正确的 XML 命名空间声明如下:如果您已经这样做了,那么它只能意味着您在没有预安装 JSTL 的服务器上运行 web 应用程序。成熟的 Java EE 应用服务器(例如 Glassfish 和 JBoss AS)已经捆绑了 JSTL,但简单的 Servlet 容器(例如 Tomcat 和 Jetty)却没有。您需要下载 JSTL 库并将其放入 web 应用程序的
/WEB-INF/lib
中,甚至可能放入服务器自己的/lib
文件夹中。另请参阅:
与具体内容无关的 下载链接和安装说明问题,您是否清楚
是视图构建时间标记,而不是视图渲染时间标记?如果您实际上正在寻找后者,那么您应该使用 Facelets 自己的
标签代替。另请参阅 JSF2 Facelets 中的 JSTL...有意义吗?Open the page in the webbrowser, rightclick and View Source. You see the
<c:forEach>
tag plain vanilla in there, right? It is not been parsed and executed at all? This is not right. You need to ensure that you have declared the JSTL core taglib in the XML namespace in order to get it to be parsed and executed by Facelets. The proper XML namespace declaration is the following:If you have already done it, then it can only mean that you're running the webapp on a server which does not have JSTL preinstalled. Full fledged Java EE application servers like Glassfish and JBoss AS already ship with JSTL bundled, but simple servlet containers like Tomcat and Jetty not. You'd need to download and put the JSTL library in webapp's
/WEB-INF/lib
or maybe even in server's own/lib
folder.See also:
Unrelated to the concrete problem, are you well aware that the
<c:forEach>
is a view build time tag, not a view render time tag? If you're actually looking for the latter, then you should be using Facelets' own<ui:repeat>
tag instead. See also JSTL in JSF2 Facelets... makes sense?