例 :
<p:dataGrid var="dRow" value="#{testBean}" lazy="true" rows="1" columns="1">
    <p:carousel var="cRow" value="#{dRow.subCategories}" headerText="#{dRow.catName}" itemStyle="width : 300px">
        <!--Show images but that part is excluded for brevity.-->
        <p:commandLink process="@this" value="#{cRow.subCatName}" actionListener="#{testBean.action(cRow)}"/>
    </p:carousel>
</p:dataGrid>
マネージド Bean :
@Named
@RequestScoped
public class TestBean extends LazyDataModel<Category> {
    @Inject
    private DataStore dataStore;
    private List<Category> categories;
    public TestBean() {}
    @PostConstruct
    private void init() {
        categories = dataStore.getCategories();
    }
    @Override
    public List<Category> load(int first, int pageSize, String sortField, SortOrder sortOrder, Map<String, Object> filters) {
        List<Category> list = dataStore.getCategories();
        setRowCount(list.size());
        return list;
    }
    public List<Category> getCategories() {
        return categories;
    }
    public void action(SubCategory subCategory) {
        System.out.println("action() invoked : " + subCategory.getSubCatName());
    }
}
豆は で飾られてい@RequestScopedます。が作成および格納されるDataStoreアプリケーション スコープの Beanです。List<Category>
指定されたコマンド リンクは、マネージド Bean でアクション リスナー メソッド ( ) をトリガーしません。action()ただし、Bean が装飾されている@ViewScoped(または幅が広い) か、遅延データ モデルが削除されている場合を除きます。
このように、変化して、
<p:dataGrid var="dRow" value="#{testBean}" .../>
に
<p:dataGrid var="dRow" value="#{testBean.categories}" .../>
つまり、<p:commandLink>指定されたアクション リスナーが呼び出されます (遅延データ モデルはここでは除外されます。指定されたものは、バッキング Bean から<p:dataGrid>直接入力されます)。List<Category>
もう 1 つの方法は、前述のビュー スコープ Bean のような、より広いスコープ Bean を使用することです。
コンポーネント内のコマンドコンポーネントが機能するように、特定の状況で遅延データモデルとともにリクエストスコープの Bean を使用することは可能ですか? <p:commandLink>s が a<p:carousel>によってラップされているという理由だけで、そのようなビュースコープの Bean がたくさんあり<p:dataGrid>ます。
リストが維持されるアプリケーション スコープの Bean とドメイン モデル クラスが必要な場合。
アプリケーション スコープの Bean :
@Named
@ApplicationScoped
public class DataStore {
    private List<Category> categories;
    public DataStore() {}
    @PostConstruct
    private void init() {
        categories = new ArrayList<>();
        Category category = new Category();
        category.setCatId(1L);
        category.setCatName("Animals");
        categories.add(category);
        List<SubCategory> subCategories = category.getSubCategories();
        SubCategory subCategory = new SubCategory();
        subCategory.setSubCatId(1L);
        subCategory.setSubCatName("Aquatic");
        subCategory.setCategory(category);
        subCategories.add(subCategory);
        subCategory = new SubCategory();
        subCategory.setSubCatId(2L);
        subCategory.setSubCatName("Aerial");
        subCategory.setCategory(category);
        subCategories.add(subCategory);
        subCategory = new SubCategory();
        subCategory.setSubCatId(3L);
        subCategory.setSubCatName("Mammals");
        subCategory.setCategory(category);
        subCategories.add(subCategory);
    }
    public List<Category> getCategories() {
        return categories;
    }
}
ドメインクラスCategory:
public class Category implements Serializable {
    private Long catId;
    private String catName;
    private List<SubCategory> subCategories = new ArrayList<>();
    private static final long serialVersionUID = 1L;
    public Category() {}
    public Long getCatId() {
        return catId;
    }
    public void setCatId(Long catId) {
        this.catId = catId;
    }
    public String getCatName() {
        return catName;
    }
    public void setCatName(String catName) {
        this.catName = catName;
    }
    public List<SubCategory> getSubCategories() {
        return subCategories;
    }
    public void setSubCategories(List<SubCategory> subCategories) {
        this.subCategories = subCategories;
    }
    @Override
    public int hashCode() {
        int hash = 7;
        hash = 47 * hash + Objects.hashCode(getCatId());
        return hash;
    }
    @Override
    public boolean equals(Object that) {
        if (!(that instanceof Category)) {
            return false;
        }
        return this == that || Objects.equals(getCatId(), ((Category) that).getCatId());
    }
    @Override
    public String toString() {
        return String.format("%s[catId=%d]", getClass().getCanonicalName(), getCatId());
    }
}
ドメインクラスSubCategory:
public class SubCategory implements Serializable {
    private Long subCatId;
    private String subCatName;
    private Category category;
    private static final long serialVersionUID = 1L;
    public SubCategory() {}
    public Long getSubCatId() {
        return subCatId;
    }
    public void setSubCatId(Long subCatId) {
        this.subCatId = subCatId;
    }
    public String getSubCatName() {
        return subCatName;
    }
    public void setSubCatName(String subCatName) {
        this.subCatName = subCatName;
    }
    public Category getCategory() {
        return category;
    }
    public void setCategory(Category category) {
        this.category = category;
    }
    @Override
    public int hashCode() {
        int hash = 7;
        hash = 47 * hash + Objects.hashCode(getSubCatId());
        return hash;
    }
    @Override
    public boolean equals(Object that) {
        if (!(that instanceof SubCategory)) {
            return false;
        }
        return this == that || Objects.equals(getSubCatId(), ((SubCategory) that).getSubCatId());
    }
    @Override
    public String toString() {
        return String.format("%s[subCatId=%d]", getClass().getCanonicalName(), getSubCatId());
    }
}