如何在不关闭素数中的ajax调用后关闭组件的情况下更新p:selectCheckboxMenu的标签?

2022-09-03 13:22:34

当我尝试从后备 Bean 动态生成标签时,会出现一个问题。问题是,对于每个选择,显示的下拉列表都会消失,但标签已正确更新。是否有解决此问题的方法?

<p:selectCheckboxMenu value="#{formBean.selectedMovies}" label="#{formBean.moviesLabel}"    id="Movies" >
    <f:selectItems value="#{formBean.movies}" ></f:selectItems>
    <p:ajax update="Movies" listener="#{formBean.populateLabel}"></p:ajax>
</p:selectCheckboxMenu>

//Backing bean 
public void populateLabel() {
    /* Populating the label with the selected options */
    moviesLabel = new String("");
    if (selectedMovies.size() == 0) {
        moviesLabel = "Select";
    } else {
        for (int i = 0; i < selectedMovies.size(); i++) {
            if (moviesLabel.length() == 0) {
                moviesLabel = selectedMovies.get(i);
            } else {
                moviesLabel = moviesLabel + "," + selectedMovies.get(i);
            }
        }
    }
}

答案 1

操作方法如下

添加到您的widgetVar="someVarName"p:selectCheckboxMenu

并通过添加p:"ajaxoncomplete="someVarName.show()"

完整代码 :

<p:selectCheckboxMenu widgetVar="someVarName" value="#{usersManagmentPage.selectedMovies}" 
        label="#{usersManagmentPage.moviesLabel}"   id="Movies" >
    <f:selectItems value="#{usersManagmentPage.movies}" ></f:selectItems>
    <p:ajax oncomplete="someVarName.show()" listener="#{usersManagmentPage.populateLabel}" update="Movies" ></p:ajax>
</p:selectCheckboxMenu>

在最新的PrimeFaces中,您应该使用而不是oncomplete="PF('someVarName').show()"oncomplete="someVarName.show()"


答案 2