迭代 h:datatable 中的嵌套 List 属性 [英] Iterate over nested List property inside h:datatable
问题描述
<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>
我有一个实体成员,他的一个财产是带有 get/set 的列表照片该属性已填充我不知道如何在 jsf 中获取该值,我只想要每个成员的第一张照片,因为他们有 2-3 张照片.那有可能吗??任何其他解决方案将不胜感激.
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.
推荐答案
只需使用
或
迭代它通常的方式.将多个迭代组件相互嵌套是完全有效的.对于
,你只需要确保将嵌套的迭代组件放在
中.
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>
.
例如
<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>
或
<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>
当您嵌套多个 <ui:repeat>
组件并在其中使用 <f:ajax>
而使用较旧的组件时,您可能只会遇到问题Mojarra 版本.
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.
只有 JSTL
在嵌套在 JSF 迭代组件中时不起作用,原因在此说明 JSF2 Facelets 中的 JSTL ......有意义吗?
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?
与具体问题无关,请不要滥用
进行纯文本展示.它生成一个 HTML 元素,该元素旨在 label
for
属性的输入元素.但是,您在代码中没有这样做.您应该使用
代替.顺便说一句,我最近在初学者代码中更频繁地看到这一点.一定有一个糟糕的教程或资源以这种方式滥用
而不是
甚至模板文本中的普通 EL.您使用的是哪个教程/资源?然后我可以就这个严重的错误指示联系作者.另请参见 h:outputLabel 的用途及其for"属性
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
这篇关于迭代 h:datatable 中的嵌套 List 属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!