所以我有一个如下的extendedDataTables(代码被缩短以保持简单)。
<rich:extendedDataTable value="#{package.packageList}" var="o"
styleClass="listStyle" selection="#{package.selection}"
selectionMode="single">
<a4j:ajax execute="@form" event="selectionchange"
listener="#{package.selectionListener}" render=":res" />
<rich:column>
<f:facet name="header">Package ID</f:facet>
#{o.packageID}
</rich:column>
</rich:extendedDataTable>
因此,当用户单击它时,它会将其详细信息输出到后面的 a4j:outputPanel 内的另一个表中。
<a4j:outputPanel id="res">
<rich:panel header="Selected Package"
rendered="#{not empty package.selectionPackage}">
</rich:panel>
</a4j:outputPanel>
这部分有效。然而,这个新细节现在包含几个变量以及一个我还需要能够选择的对象的数组列表。所以这个 arrayList 生成它自己的扩展数据表,然后我需要选择并检索它的信息。这部分是它正在破坏的地方。到目前为止,我尝试过的内容如下。
<a4j:outputPanel id="res">
<rich:panel header="Selected Package"
rendered="#{not empty package.selectionPackage}">
<rich:dataTable value="#{package.selectionPackage}"
var="extensionTable" styleClass="listStyle" selectionMode="single">
<rich:column>
<rich:extendedDataTable value="# {extensionTable.extensionList}"
var="selectedExtension" styleClass="listStyle" style="height:200px;"
selection="#{package.extensionSelection}" selectionMode="single">
<a4j:ajax execute="@form" event="selectionchange"
listener="#{package.selectionExtensionListener}" render=":extensions" />
<rich:column>
<f:facet name="header">Extension Add on list</f:facet>
#{selectedExtension.extensionName}"
</rich:column>
</rich:extendedDataTable>
</rich:column>
</rich:dataTable>
</rich:panel>
</a4j:outputPanel>
我有另一个 a4j 面板来处理新的扩展选定对象。问题是我的 selectedExtensionListener 没有被调用。我不知道为什么,我正在尝试甚至可能。选择正在工作,因为行正在改变颜色,但从未调用 selectionExtensionListener。我有一些 system.out.printlnts 只是为了检查,而第一个侦听器被称为第二个侦听器。如果这很明显或什至不可能,请原谅我,但我对 jsf 比较陌生。任何帮助将不胜感激。
我将在下面复制并粘贴我的 bean 以向您展示代码的后端。我将排除声明我的所有变量并填充我的列表和对象等,因为它只会阻塞代码,如果你需要它们,请告诉我,我会编辑它们。(抱歉格式化,我不知道你是否可以在这里格式化代码吗?)
public class Package implements Serializable{
public void selectionListener(AjaxBehaviorEvent event) {
System.out.println("In selection listener");
UIExtendedDataTable dataTable = (UIExtendedDataTable) event.getComponent();
Object originalKey = dataTable.getRowKey();
selectionPackage.clear();
for (Object selectionKey : selection) {
dataTable.setRowKey(selectionKey);
if (dataTable.isRowAvailable()) {
selectionPackage.add((PackageClass) dataTable.getRowData());
}
}
dataTable.setRowKey(originalKey);
}
public void selectionExtensionListener(AjaxBehaviorEvent event) {
System.out.println("Testing 1");
UIExtendedDataTable dataTable = (UIExtendedDataTable) event.getComponent();
Object originalKey = dataTable.getRowKey();
selectionExtension.clear();
for (Object selectionKey : extensionSelection) {
dataTable.setRowKey(selectionKey);
if (dataTable.isRowAvailable()) {
System.out.println("Testing 2");
selectionExtension.add((ExtensionClass) dataTable.getRowData());
}
}
dataTable.setRowKey(originalKey);
}
public Collection<Object> getSelection() {
return selection;
}
public void setSelection(Collection<Object> selection) {
this.selection = selection;
}
public Collection<Object> getExtensionSelection() {
return extensionSelection;
}
public void setExtensionSelection(Collection<Object> extensionSelection) {
this.extensionSelection = extensionSelection;
}
public List<PackageClass> getPackageList() {
return packageList;
}
public void setPackageList(ArrayList<PackageClass> packageList) {
this.packageList = packageList;
}
public PackageClass getSelectionPackage() {
if (selectionPackage == null || selectionPackage.isEmpty()) {
return null;
}
return selectionPackage.get(0);
}
public void setSelectionPackage(ArrayList<PackageClass> selectionPackage) {
this.selectionPackage = selectionPackage;
}
public ArrayList<PackageClass> getSelectionPackages() {
return selectionPackage;
}
public ExtensionClass getSelectionExtension() {
if (selectionExtension == null || selectionExtension.isEmpty()) {
return null;
}
return selectionExtension.get(0);
}
public void setSelectionExtension(ArrayList<ExtensionClass> selectionExtension) {
this.selectionExtension = selectionExtension;
}
public ArrayList<ExtensionClass> getSelectionExtensions() {
return selectionExtension;
}
}