当我尝试从备用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
widgetVar="someVarName"
p:selectCheckboxMenu
并p:"ajax通过添加修改您的oncomplete="someVarName.show()"
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()"
oncomplete="PF('someVarName').show()"