当我尝试从备用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);
            }
        }
    }
}

最佳答案

这是怎么

widgetVar="someVarName"添加到您的p:selectCheckboxMenu
并通过添加p:"ajax修改oncomplete="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()"

10-08 08:01