我有一个带有延迟加载数据表的复合组件。我需要在同一页面上多次呈现此组件。我还需要在表格上启用单行选择。问题是在rowSelect事件中,只有页面最后渲染的表返回选择对象,其他表返回null。
组件 kwe:lazytable:
<composite:interface>
<composite:attribute name="bean" required="true" />
<composite:attribute name="groupId" required="true" />
</composite:interface>
<composite:implementation>
<p:dataTable id="entityTable" widgetVar="entityTable" var="entity" value="#{cc.attrs.bean.loadEntities(cc.attrs.groupId)}"
rows="5" resizableColumns="true" lazy="true" selectionMode="single">
<p:ajax event="rowSelect" listener="#{cc.attrs.bean.onRowSelect}" />
...
</p:dataTable>
</composite:implementation>
多次渲染:
<kwe:lazytable bean="#{cc.attrs.bean}" groupId="#{1}" />
<kwe:lazytable bean="#{cc.attrs.bean}" groupId="#{2}" />
<kwe:lazytable bean="#{cc.attrs.bean}" groupId="#{3}" />
在 backing bean 中,LazyDataModels 存储在 map 中:
@ManagedBean
@ViewScoped
public class SearchBean {
private Map<Integer, LazyEntitiesDataModel> lazyEntitiesMap = new HashMap<>();
public LazyDataModel<T> loadEntities(int groupId) {
LazyEntitiesDataModel entities = lazyEntitiesMap.get(groupId);
if (entities == null) {
entities = new LazyEntitiesDataModel();
lazyEntitiesMap.put(groupId, entities);
}
return entities;
}
public void onRowSelect(SelectEvent event) {
System.out.println(event.getObject());
}
}
如果我放了同样的事情selection="#{cc.attrs.bean.selectedentity}"
如果我放入数据表声明,只有在从最后一个表中选择一行时才会填充它。
有人知道为什么这不起作用吗?