在Datatable JSF中显示Set集合中的对象不起作用 [英] Displaying objects from a Set collection in Datatable JSF does not work
问题描述
诸如 Set< MyObject>之类的原因objects = new HashSet< MyObject>();
不应该在JSF Datatable中工作?它适用于List。
Any reason why a such asSet<MyObject> objects = new HashSet<MyObject>();
shouldn't work in the JSF Datatable? It works with List.
推荐答案
至于为什么 设置
,这是因为此数据结构从未打算过保存按索引排序的对象集合。 列表
这样做,这个数据结构是最明智的数据结构来表示 UIData
组件。 DataModel
interface,表示 UIData <的包装值/ code>
组件并保存行索引并记住当前行以进行迭代渲染和表单提交处理回发,仅支持来自Java集合类的 列表
接口的风格为 ListDataModel
。
As to why a Set
in general isn't supported, this is because this data structure is never intented to hold a collection of objects which is ordered by an index. The List
does that and this data structure is the most sensible data structure to represent the value of an UIData
component. The DataModel
interface, which represents the wrapped value of the UIData
components and holds the row indexes and remembers the current row for iteration on render and form submit processing on postback, supports from the Java collection classes only the List
interface in flavor of ListDataModel
.
经过漫长的决策过程(特别是由Hibernate / JPA社区推动,他们通常使用 设置
的nm关系),JSF规范团队已经为即将到来的JSF 2.2决定放弃e DataModel
界面支持 Collection
界面而不是单独的 列表
,借助新的 CollectionDataModel
实现。这也支持集合。另请参见 JSF规范问题479 。您应该记住使用 LinkedHashSet
而不是 HashSet
,当然如果你想要一个可编辑的数据表。 LinkedHashSet
维护元素的顺序。
After a long decision process (especially pushed by Hibernate/JPA community who generally uses Set
for n-m relationships), the JSF spec team has for the upcoming JSF 2.2 finally decided to let the DataModel
interface support the Collection
interface instead of alone the List
, with help of the new CollectionDataModel
implementation. This supports sets as well. See also JSF spec issue 479. You should only keep in mind to use LinkedHashSet
instead of HashSet
, certainly if your intention is to have an editable data table. A LinkedHashSet
maintains the ordering of the elements.
这篇关于在Datatable JSF中显示Set集合中的对象不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!