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.
在网络浏览器中打开页面,右键单击并查看源代码.您会在其中看到<c:forEach>
标签普通香草,对吗?它根本没有被解析和执行吗?这个不对.您需要确保已在XML名称空间中声明了JSTL核心taglib,以使其可以由Facelets解析和执行.正确的XML名称空间声明如下:
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:
xmlns:c="http://java.sun.com/jsp/jstl/core"
如果您已经完成此操作,则仅意味着您正在未预装JSTL的服务器上运行webapp.诸如Glassfish和JBoss AS之类的成熟Java EE应用服务器已经捆绑了JSTL,但没有像Tomcat和Jetty这样的简单servlet容器.您需要下载JSTL库并将其放在webapp的/WEB-INF/lib
中,甚至可能放在服务器自己的/lib
文件夹中.
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.
- 我们的JSTL标签Wiki页面-包含下载链接和安装说明
- Our JSTL tag wiki page - contains download links and installation instructions
无关与具体问题无关,您是否知道<c:forEach>
是视图构建时间标签,而不是视图渲染时间标签?如果您实际上正在寻找后者,那么您应该使用Facelets自己的 JSF2 Facelets中的JSTL ...有意义吗?
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?