2011-10-22 33 views
2

UI的文檔:在JSF 2.0 repeat標籤說,你可以遍歷一個結果,但我的代碼:使用UI:重複輸出的ResultSet

<ui:repeat value="#{bean.resultSet}" var="row" varStatus="status"> 
    #{row.string("mySQLColumn")} 
</ui:repeat> 

產生這個錯誤:

javax.faces.FacesException: Iteration start index is greater than the number of available rows. 
    at com.sun.faces.facelets.component.UIRepeat.validateIterationControlValues(UIRepeat.java:682) 
    at com.sun.faces.facelets.component.UIRepeat.process(UIRepeat.java:505) 
    at com.sun.faces.facelets.component.UIRepeat.encodeChildren(UIRepeat.java:974) 
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1756) 
    at javax.faces.render.Renderer.encodeChildren(Renderer.java:168) 
+0

這似乎至少發生在空'ResultSet'上。我希望它不會在這種情況下迭代,但會拋出異常。 –

回答

1

雖然它似乎被支持作爲迭代的參數,但最好先將它轉換爲List然後迭代。

這樣你就不會將數據庫訪問技術傳播到視圖層。

+1

爲什麼文檔說value屬性可以包含ResultSet? http://download.oracle.com/javaee/6/javaserverfaces/2.1/docs/vdldocs/facelets/ui/repeat.html – Adam

+0

嗯,有趣。它似乎可以,但最好不要將它傳播到視圖層。 – Bozho