2013-05-16 54 views
1
<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张照片。它有可能?任何其他解决方案将不胜感激。迭代里面^ h嵌套列表属性:数据表

+0

如果您有'List'类型的'entry.list',可以使用EL'empty'检查其内容,然后使用'[0]'访问其第一个元素,如果我有你的想法正常。 – skuntsel

回答

6

只需使用<ui:repeat><h:dataTable>即可。将多个迭代组件嵌套在一起是完全有效的。如果是<h:dataTable>,则只需确保将嵌套迭代组件置于<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> 

<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>。对于原因解释这里JSTL in JSF2 Facelets... makes sense?


无关的具体问题嵌套在JSF迭代组件内时

只有JSTL <c:forEach>是行不通的,请不要为纯文本呈现滥用<h:outputLabel>。它生成一个HTML <label>元素,该元素被for属性默认为label an input element。但是,你在代码中没有做到这一点。您应该使用<h:outputText>。顺便说一下,我最近经常在首发代码中看到这种情况。必须在某处存在一个错误的教程或资源,它正在滥用<h:outputLabel>而不是<h:outputText>,甚至在模板文本中使用纯EL。你正在使用哪个教程/资源?然后我可以联系作者关于这个严重的错误指示。另请参见Purpose of the h:outputLabel and its "for" attribute

+0

告诉你真正的我的老师告诉我使用它..... – DarkVision

+0

告诉你的老师分开学习基本的HTML。他显然对HTML语义一无所知。 – BalusC

+0

@BalusC'我可以联系作者关于这个严重的错误指示'这真是个好主意。你真的很聪明。也许这是那些臭名昭着的JSF相关网站之一像roseindia? – skuntsel