Java 如何从支持 bean 刷新整个 JSF 页面
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3628722/
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 refresh entire JSF page from the backing bean
提问by droidy
We have a rich:comboBox on a JSF page which has a valueChangeListener that calls a backing bean function:
我们在 JSF 页面上有一个 rich:comboBox,它有一个调用支持 bean 函数的 valueChangeListener:
<rich:comboBox id="cbmodel" defaultLabel="${accessUtils.activeRole}" value="${accessUtils.activeRole}"
style="float: right;" valueChangeListener="${accessUtils.valueChangeListener}" >
<c:forEach var="role" items="${accessUtils.currentUserRoles}">
<f:selectItem itemValue="#{role}"/>
<a4j:support event="onchange" ajaxSingle="false" />
</c:forEach>
</rich:comboBox>
And here's the valueChangeListener backing bean function:
这是 valueChangeListener 支持 bean 函数:
public void valueChangeListener(ValueChangeEvent event){
System.out.println("EVENT: HAS BEEN CALLED " + event.getNewValue());
setActiveRole((String) event.getNewValue());
}
How can we get this function to reload the JSF page which has the rich:comboBox?
我们怎样才能让这个函数重新加载包含rich:comboBox 的JSF 页面?
Thanks for any help.
谢谢你的帮助。
采纳答案by Jose Diaz
You could use the oncomplete
attribute of the <a4j:support>
with JS to force a full page reload, if that's what you want to do, like:
您可以使用with JS的oncomplete
属性<a4j:support>
来强制整个页面重新加载,如果这是您想要做的,例如:
<a4j:support event="onchange" ajaxSingle="false" oncomplete="javascript:location.reload(true)"/>
回答by Vivien Barousse
a4j:support contains an optional reRender attribute that can force a JSF component to reload after invoking the JSF listener.
a4j:support 包含一个可选的 reRender 属性,它可以在调用 JSF 侦听器后强制 JSF 组件重新加载。
You can try with:
您可以尝试:
<a4j:support event="onchange" ajaxSingle="false" reRender="myComp" />