一尘不染

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

ajax

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

阅读 223

收藏
2020-07-26

共1个答案

一尘不染

这是怎么

添加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()"

2020-07-26