2013-05-16 59 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