0

嗨,我有一个变量

List<List<MyObject>> x = new ArrayList<List<MyObject>>();

我希望这个绑定到 jsf 中包含 select 的数据表

<datatable>
   <column>
      <Select/>
   </column>
</datatable>

这在jsf中可能吗

代码:view.xhtml

<h:dataTable id="i1" value="#{bean.listoflist}" var="list1">
  <h:column>
    <h:selectOneListbox value="#{bean.somestring}" >
      <f:selectItems value="#{list1.?}" var="any" itemValue="#{any.??}/>"
    </h:selectOneListbox> 
  </h:column>                    
</h:dataTable>`

Bean.java (name = "bean")

public class Bean implements Serializable
{
  List<List<MyObject>> listoflist = new ArrayList<List<MyObject>>()

 //--------------Getters and Setter
}

MyObject.java

 public class MyObject
 {
    private String s1;
    private String s2;
   //---------------getter and setter
 }
4

1 回答 1

2

如果我正确理解了您的问题,您想要制作一个包含选择元素的数据表,其选项来自模型的嵌套列表。如果是,这里是解决方案:

  • 根据外部列表的大小准备一个选定元素的数组;
  • 为您的模型对象提供转换器;
  • 相应地填充 UI 组件。

您可能会在下面找到一个工作示例:

<h:dataTable value="#{bean.listOfLists}" var="list" binding="#{table}" >
    <h:column>
        <h:selectOneListbox value="#{bean.selection[table.rowIndex]}" converter="myObjectConverter" >
            <f:selectItems value="#{list}" var="obj" itemValue="#{obj}" itemLabel="#{obj.s1}" />
       </h:selectOneListbox> 
   </h:column>                    
</h:dataTable>

MyObject[] selection = new MyObject[listOfLists.size()];
于 2013-10-03T00:19:40.463 回答