在JSF中以表格格式显示图像列表 [英] Display a list of images in a table format in JSF
问题描述
这可能是一个非常简单的JSF问题,但我似乎无法找到简单的答案。
This is probably a really simple JSF question, but I can't seem to find the simple answer.
我有一个图像列表,我想要将它们显示在图像表中。每个图像都显示其文件名。我正在使用 ui:repeat
标记,如下所示。我没有按要求获得5列,但只有1列。
I have a List of images, and I want to display them in a table of images. Each image is displayed with its filename. I'm using a ui:repeat
tag as shown below. I don't get 5 columns as requested, however, only 1.
<h:panelGrid id="resourcePanel" columns="5" rules="all">
<ui:repeat var="res" value="#{resourceUpload.resources}">
<h:panelGrid columns="1" rules="none">
<h:graphicImage
value="/image/resource?id=#{res.idAsString}"
style="width:100px;" />
<h:outputText value="#{res.name}" />
</h:panelGrid>
</ui:repeat>
</h:panelGrid>
推荐答案
输出完全符合预期和指定。 < ui:repeat>
是一个渲染时标记,而不是像< c:forEach> $ c $的视图构建时标记C>。构建视图后,
< h:panelGrid>
最终得到1个子组件(< ui:repeat>
本身),而不是 n 嵌套< h:panelGrid>
组件,就像您使用< c一样:&的forEach GT;
。
The output is fully as expected and specified. The <ui:repeat>
is a render time tag, not a view build time tag like <c:forEach>
. After building the view, <h:panelGrid>
ends up with 1 child component (the <ui:repeat>
itself), not with n nested <h:panelGrid>
components like as you would get with <c:forEach>
.
<html ... xmlns:c="http://java.sun.com/jsp/jstl/core">
...
<h:panelGrid id="resourcePanel" columns="5" rules="all">
<c:forEach var="res" items="#{resourceUpload.resources}">
<h:panelGrid columns="1" rules="none">
<h:graphicImage
value="/image/resource?id=#{res.idAsString}"
style="width:100px;" />
<h:outputText value="#{res.name}" />
</h:panelGrid>
</c:forEach>
</h:panelGrid>
(这在早于2.1.18的Mojarra版本中有一个暗示#{resourceUpload}
:它不能是一个视图范围的bean,它必须是由于查看状态保存/恢复中的鸡蛋问题而请求作用域;你需要升级到Mojarra 2.1.18)
(this has in the Mojarra versions older than 2.1.18 however an implication on #{resourceUpload}
: it can't be a view scoped bean, it must be request scoped due to a chicken-egg issue in view state saving/restoring; you'd need to upgrade to Mojarra 2.1.18)
您的嵌套< h:panelGrid>
由方式没有完全意义。我在这里使用了< h:panelGroup>
。
Your nested <h:panelGrid>
makes by the way no utter sense. I'd have used <h:panelGroup>
here.
- JSF2 Facelets中的JSTL ......有意义吗? - 更好地理解查看构建时间与查看渲染时间
- 在JSF中动态创建表列 - 另一个类似的问题
- JSTL in JSF2 Facelets... makes sense? - to understand "view build time" vs "view render time" better
- create table columns dynamically in JSF - another similar question
这篇关于在JSF中以表格格式显示图像列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!