我正在尝试使用扩展数据表,这是一段代码,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 上,如果我点击一行,它工作正常并将我选择的行打印到控制台(监听器中的两个打印输出)。但是当我尝试将方法availableMssList 与a4j 命令按钮一起使用时,selectionItems 似乎为空。可能是什么问题呢?
谢谢您的帮助!