2
    <h:dataTable value="#{SearchingBeans.list}" var="entry">
        <h:column>
            <f:facet name="header">
                <h:outputLabel>Photo</h:outputLabel>
            </f:facet>
        </h:column>
        <h:column>
            <f:facet name="header">
                <h:outputLabel>Pseudo</h:outputLabel>
            </f:facet>
            <h:outputLabel value="#{entry.pseudo}"></h:outputLabel>
        </h:column>
        <h:column>
            <f:facet name="header">
                <h:outputLabel>Description</h:outputLabel>
            </f:facet>
            <h:outputLabel value="#{entry.description}"></h:outputLabel>
        </h:column>
        <h:column>
            <f:facet name="header">
                <h:outputLabel>Photo</h:outputLabel>
            </f:facet>
            <h:outputLabel value="#{entry.photo[0].path}"></h:outputLabel> <-- this a List
        </h:column>
    </h:dataTable>

i got a entities member one of his property is a List photo with get/set that property is populate i don't know how to fetch that value in jsf i want only the first picture for each member since their have 2-3 photos. Its that possible?? any other solution will be appreciate.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
DarkVision
  • 1,373
  • 3
  • 20
  • 33
  • If you have `entry.list` of type `List`, you can check its contents with EL `empty` and then access its first element with `[0]`, if I've got your idea properly. – skuntsel May 16 '13 at 15:31

1 Answers1

7

Just iterate over it using <ui:repeat> or <h:dataTable> the usual way. It's perfectly valid to nest multiple iterating components in each other. In case of <h:dataTable>, you only need to make sure that you put the nested iterating component inside a <h:column>.

E.g.

<h:dataTable value="#{bean.entities}" var="entity">
    <h:column>
        #{entity.property}
    </h:column>
    <h:column>
        <ui:repeat value="#{entity.subentities}" var="subentity">
            #{subentity.property}
        </ui:repeat>
    </h:column>
</h:dataTable>

or

<h:dataTable value="#{bean.entities}" var="entity">
    <h:column>
        #{entity.property}
    </h:column>
    <h:column>
        <h:dataTable value="#{entity.subentities}" var="subentity">
            <h:column>
                #{subentity.property}
            </h:column>
        </h:dataTable>
    </h:column>
</h:dataTable>

You'll potentially only run into issues when you nest multiple <ui:repeat> components and use <f:ajax> in it while using an older version of Mojarra.

Only JSTL <c:forEach> wouldn't work when nested inside a JSF iterating component for the reasons explained here JSTL in JSF2 Facelets... makes sense?


Unrelated to the concrete problem, please don't abuse <h:outputLabel> for pure text presentation. It generates a HTML <label> element which is intented to label an input element by for attribute. However, you're doing that nowhere in the code. You should be using <h:outputText> instead. By the way, I'm lately seeing this more often in code of starters. There must be somewhere a bad tutorial or resource which is abusing the <h:outputLabel> this way instead of <h:outputText> or even plain EL in template text. Which tutorial/resource was you using? Then I can contact the author about this severe misinstruction. See also Purpose of the h:outputLabel and its "for" attribute

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Tell your teacher to take time apart to learn basic HTML. He clearly knows nothing about HTML semantics. – BalusC May 16 '13 at 15:34
  • @BalusC 'I can contact the author about this severe misinstruction' that's a really great idea. And you're really ingenious about it. Maybe it's one of those notorious JSF-related sites like roseindia? – skuntsel May 16 '13 at 15:38
  • How simple it is , but we make it so complicated – Chinmoy Jan 09 '18 at 10:28