本文介绍了如何在primefaces中的ajax调用后不关闭组件的情况下更新p:selectCheckboxMenu的标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我尝试从支持 bean 动态生成标签时出现一个问题.问题是每个选择出现的下拉列表都会消失,但标签会正确更新.有解决方法吗?
There is one problem occurring when I am trying to dynamically generate the label from the backing bean. The problem is that the dropdown that appears vanishes for each selection but the label is updated properly. Is there a workaround for this?
<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
并通过添加 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()"
In latest PrimeFaces you should use oncomplete="PF('someVarName').show()"
instead of oncomplete="someVarName.show()"
这篇关于如何在primefaces中的ajax调用后不关闭组件的情况下更新p:selectCheckboxMenu的标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!