我正在尝试使用extendedDataTable,这里是代码的一部分,xhtml部分:
<h:form>
<rich:extendedDataTable id="network_table" value="#{NetworkBean.availableNetworkList()}" var="network" selection="#{NetworkBean.selection}" selectionMode="single" >
<a4j:ajax execute="@form" event="selectionchange" listener="#{NetworkBean.selectionListener}"/>
<rich:column>
<f:facet name="header">Available Networks</f:facet>
<h:outputText value="#{network}"/>
</rich:column>
</rich:extendedDataTable>
<a4j:commandButton value="1" action="#{NetworkBean.availableMssList()}">
</a4j:commandButton >
</h:form>
和支持bean的某些部分:
private Collection<Object> selection;
private List<String> selectionItems = new ArrayList<String>();
public void selectionListener(AjaxBehaviorEvent event) {
UIExtendedDataTable dataTable = (UIExtendedDataTable) event.getComponent();
Object originalKey = dataTable.getRowKey();
selectionItems.clear();
for (Object selectionKey : selection) {
dataTable.setRowKey(selectionKey);
if (dataTable.isRowAvailable()) {
System.out.print((String) dataTable.getRowData());
selectionItems.add((String) dataTable.getRowData());
System.out.print(selectionItems);
}
}
dataTable.setRowKey(originalKey);
}
public Collection<Object> getSelection() {
return selection;
}
/**
* @param selection the selection to set
*/
public void setSelection(Collection<Object> selection) {
this.selection = selection;
}
/**
* @return the selectionItems
*/
public String getSelectionItem() {
if (selectionItems == null || selectionItems.isEmpty()) {
return null;
}
return selectionItems.get(0);
}
public List<String> getSelectionItems() {
return selectionItems;
}
/**
* @param selectionItems the selectionItems to set
*/
public void setSelectionItems(List<String> selectionItems) {
this.selectionItems = selectionItems;
}
public void availableMssList(){
System.out.print("hithere");
System.out.println(selectionItems);
}
所以我的问题在于selectionItems,如果我点击一行它工作正常并将选定的行打印到控制台(监听器中的两个打印输出)。但是当我尝试使用带有a4j命令按钮的availableMssList方法时,selectionItems似乎是空的。可能是什么问题?
感谢您的帮助!