渲染多个数据表时,rowSelect事件返回null

时间:2013-07-14 10:41:08

标签: java jsf jsf-2 primefaces

我有一个带有延迟加载数据表的复合组件。我需要在同一页面上多次渲染此组件。我还需要在表上启用单行选择。问题是在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}" />

在支持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}"放在数据表声明中,就会发生同样的事情。仅在从最后一个表中选择一行时填充它。

有人知道为什么这不起作用吗?

0 个答案:

没有答案