我在ViewScope模式下有一个Managed Bean.因此,当我从此Managed Bean调用某个操作时,我的页面不会更新.我看到我的动作被很好地调用并返回null(viewscope工作流程正常).
那么,我做错了什么?
如果我使用Ajax重新渲染页面,它可以正常工作.
编辑:
我的版本是:
JSF 2.1.14与Primefaces 3.4.1
我的代码:
@ManagedBean(name = "test")
@ViewScoped
public class TestMB implements Serializable {
private String status;
public String getStatus() { return this.status; }
public void setStatus(String status) { this.status = status; }
public String changeStatus() {
this.status = "ViewScope Works!";
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
我的页面:
<!DOCTYPE HTML>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
template="/template/ui.xhtml">
<ui:define name="head">
</ui:define>
<ui:define id="teste" name="content">
<h:form id="form">
<h:outputText id="status" value="OK?: #{test.status}" />
<p:commandButton id="myAction" value="Do it!" action="#{test.changeStatus}" />
</h:form>
</ui:define>
</ui:composition>
Run Code Online (Sandbox Code Playgroud)
在我的屏幕上,状态变量不会改变.并且,是的..行动被称为OK.一些提示?
您<p:commandButton>用来提交表单.它默认发送一个ajax请求.它默认更新没有.因此,您正在观察的行为是完全可以预期的.有几种方法可以解决这个"问题"(引用,因为它实际上不是一个问题,而只是一个概念上的误解):
告诉它不要使用ajax.
<p:commandButton ... ajax="false" />
Run Code Online (Sandbox Code Playgroud)告诉它更新表格.
<p:commandButton ... update="@form" />
Run Code Online (Sandbox Code Playgroud)替换为标准JSF组件,默认情况下不使用ajax.
<h:commandButton ... />
Run Code Online (Sandbox Code Playgroud)请注意,此具体问题与视图范围本身无关.使用另一个范围(包括请求范围)时,您会遇到完全相同的问题(使用完全相同的解决方案).
| 归档时间: |
|
| 查看次数: |
4723 次 |
| 最近记录: |