0

遅延ロードされたデータテーブルを持つ複合コンポーネントがあります。このコンポーネントを同じページに複数回レンダリングする必要があります。テーブルでも単一行選択を有効にする必要があります。問題は、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 では、LazyDataModel がマップに格納されます。

@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}"I をdatatable 宣言に入れると、同じことが起こります。最後のテーブルから行を選択する場合にのみ設定されます。

なぜこれがうまくいかないのか、誰にも分かりますか?

4

0 に答える 0