jsf - 更新 View 中的项目

标签 jsf primefaces ajax-update

我正在尝试进行产品研究。

我的观点是这样的:

<h:form>
    <p:layoutUnit  position="center">
        <ui:include src="/Desktop/Users/Include/featureCheckbox.xhtml"/>     
    </p:layoutUnit>
    <p:layoutUnit position="south" style="border: 0px">
        <p:commandButton value="Search" 
                         actionListener="#{productsController.searchProdByFeatures()}"
                         oncomplete="listProd.show();"/>
    </p:layoutUnit>
</h:form>
<p:panel widgetVar="listProd" >
    <ui:include src="/Desktop/Users/Include/productsScroller.xhtml"/>
</p:panel>

这是 productsScroller.xhtml

OT:我不知道为什么我必须使用它来查看更多数据,只是滚动不起作用...

<h:form prependId="false"> 
    <p:dataScroller value="#{productsController.items}" var="item" chunkSize="10">
        <f:facet name="header">
            Scroll Down to Load More Wheelchair
        </f:facet>

        <h:panelGrid columns="1" style="width:100%" >
            <p:outputPanel>
                <h:outputText value="#{item.name}" style="font-weight: bold"/>
            </p:outputPanel>
        </h:panelGrid>
        <f:facet name="loader">
            <p:commandButton type="button" value="View More" />
        </f:facet>
    </p:dataScroller>
</h:form>

这是 productsController(@Named 和 @ViewScoped)

...
private Collection<Product> items;
private Collection<Product> selectedItems;


public Collection<Product> getSelectedItems() {
    return selectedItems;
}

public void setSelectedItems(Collection<Product> selectedItems) {
    this.selectedItems = selectedItems;
}

public Collection<Product> getItems() {
    if (items == null) {
        items = this.ejbFacade.findAll();
    }
    System.out.println(items.size());
    return items;
}

public void setItems(Collection<Product> items) {
    this.items = items;
}

public void searchProdByFeatures (){
    List<Product> items= (List<Product>) getItems();
    List<Product> newItems;
    Collection<Feature> featuresCollection = featureController.getSelectedItems();
    List<Feature> selectedFeatures = new ArrayList<>(featuresCollection);
    System.out.println(selectedFeatures.size());    //just for debug
    try {
        for (Feature selectedFeature : selectedFeatures) {
            String msg=(selectedFeature.getName()+" / ");
            System.out.println(selectedFeature.getName());
        }
        newItems=productFacade.findProdByFeatures(selectedFeatures, items);
        System.out.println("Searched product are "+newItems.size());    //just for debug        
        setItems(newItems);
        System.out.println("New items are "+getItems().size());   //just for debug     
    } catch (NotFoundException e) {
        setItems(null);
        JsfUtil.addErrorMessage(e.getMessage());
    }
}

方法searchProdByFeatures()效果很好,但问题是 dataScroller 不会更新... 我知道 View 有问题......但是什么?

或者从 Controller 更新 View 会更好?怎么办?

最佳答案

编辑代码以通过添加 update="yourIddataScroller" 来更新 dataScroller

<p:commandButton value="Search" 
                         actionListener="#{productsController.searchProdByFeatures()}"
                         oncomplete="listProd.show();" update="yourIddataScroller"/>

关于jsf - 更新 View 中的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37527131/

相关文章:

jsf - 使用复合组件将列添加到 Primefaces PanelGrid

jsf - Ajax 更新/渲染不适用于具有渲染属性的组件

jsf - 如何通过导航菜单ajax刷新动态包含内容? (JSF SPA)

java - 我如何让 "p:focus"在这个简单的应用程序中正常工作(目前根本不是 "focusing")

json - 如何从 JSF 生成 JSON 响应?

css - PrimeFaces 面板样式内容 CSS

jsf - IntelliJ 检查以查找没有 'id' 属性的标签

ajax - 无法捕获 JSF 2 应用程序上的 ajax 错误

jsf-2 - 在 rowEditor 更新模型之前显示 confirmDialog