JSF Composite 组件迭代并显示对象列表
在 JSP 和 JSTL 中,我通常会做这样的事情:
<c:forEach items="${userList}" var = "user">
<div id = "user-block">
<h1>${user.name}</h1>
<div id = "user-description">
<p>${user.description}</p>
</div>
<ul>
<li> Age: ${user.age} </li>
<li> City: ${user.city} </li>
<li> Country: ${user.country} </li>
</ul>
</div>
</c:forEach>
我试图使用 Facelet 复合组件获得相同的结果:
<cc:interface>
<cc:attribute name="value" type="java.util.List" required="true" shortDescription="The list of objects that should be displayed"/>
</cc:interface>
<cc:implementation>
<div class = "event-block">
</div>
</cc:implementation>
问题是我不知道如何迭代 #{cc.attrs.value} 中的对象。
LE: 我想知道是否有办法在不使用 JSP 或 JSTL 的情况下解决这个问题
In JSP and JSTL I would normaly do something like this:
<c:forEach items="${userList}" var = "user">
<div id = "user-block">
<h1>${user.name}</h1>
<div id = "user-description">
<p>${user.description}</p>
</div>
<ul>
<li> Age: ${user.age} </li>
<li> City: ${user.city} </li>
<li> Country: ${user.country} </li>
</ul>
</div>
</c:forEach>
I'm trying to gain the same result using Facelet Composite Components:
<cc:interface>
<cc:attribute name="value" type="java.util.List" required="true" shortDescription="The list of objects that should be displayed"/>
</cc:interface>
<cc:implementation>
<div class = "event-block">
</div>
</cc:implementation>
The problem is that I don't know how to iterate over the objects in #{cc.attrs.value}.
LE:
I would like to know if there is a way to solve this without using JSP or JSTL
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
ui:repeat
而不是c:forEach
。请参阅 https://rogerkeays.com/jsf-c-foreach-vs-ui -repeat 用于进一步比较
c:forEach
和ui:repeat
。Use
ui:repeat
instead ofc:forEach
.See https://rogerkeays.com/jsf-c-foreach-vs-ui-repeat for further comparison of
c:forEach
andui:repeat
.您可以使用
#{cc.attrs.value}
引用该列表。它会是这样的:You can refer to the list with
#{cc.attrs.value}
. It would be something like: