javascript 如何在primefaces中的ajax调用后不关闭组件的情况下更新p:selectCheckboxMenu的标签?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9964759/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to update the label of p:selectCheckboxMenu without the component being closed after ajax call in primefaces?
提问by Sri Harsha
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?
当我尝试从支持 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>
and
和
//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);
}
}
}
}
回答by Daniel
Here is how
这是如何
add widgetVar="someVarName"
to your p:selectCheckboxMenu
添加widgetVar="someVarName"
到您的p:selectCheckboxMenu
and modify your p:"ajax
by adding oncomplete="someVarName.show()"
并p:"ajax
通过添加修改您的oncomplete="someVarName.show()"
complete code :
完整代码:
<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>
In latest PrimeFacesyou should use oncomplete="PF('someVarName').show()"
instead of oncomplete="someVarName.show()"
在最新的 PrimeFaces 中,您应该使用oncomplete="PF('someVarName').show()"
而不是oncomplete="someVarName.show()"