Display a list of images in a table format in JSF

南楼画角 提交于 2019-12-03 08:57:43
BalusC

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>

(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)

Your nested <h:panelGrid> makes by the way no utter sense. I'd have used <h:panelGroup> here.

See also:

Why do you use another <h:panelGrid> inside the <ui:repeat>? You can just use a div like this.
Instead of

<h:panelGrid columns="1" rules="none">

use

<div style="display:inline-block;">

Edit:


I don't think that you can do it with <ui:repeat>. Use <c:forEach> instead.

First you should import the namespace

xmlns:c="http://java.sun.com/jstl/core"

Now replace the <ui:repeat> with <c:forEach> like this.

<c:forEach items="#{accountMastList.resultList}" var="res">
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!