我对 PrimeFaces 组件发送的第一个ajax 请求有疑问。它发生在很多情况下,所以我尝试做一个非常小的例子。我的 xhtml 文件如下:
<html
xmlns="http://www.w3c.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Remote Command Tutorial</title>
</h:head>
<h:body id="body">
<h:outputScript library="primefaces" name="jquery/jquery.js" target="head" />
<h:form id="form">
<h:inputText converter="javax.faces.Integer" id="input" value="#{remoteCommandBean.value}"></h:inputText>
<script type="text/javascript">
function increment() {
var value = parseInt($("#form\\:input").val())+1 ;
$("#form\\:input").val(value) ;
}
</script>
<h:commandButton type="submit" onclick="increment()" update="input">
<f:ajax></f:ajax>
</h:commandButton>
<p:commandButton type="submit" onclick="increment()" update="input"/>
</h:form>
</h:body>
</html>
和托管bean:
package test;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
@ManagedBean
@ViewScoped
public class RemoteCommandBean implements Serializable {
private static final long serialVersionUID = 1L;
private int value = 0;
public int getValue() {
return value;
}
public void setValue(int value) {
this.value = value;
}
}
因此,小应用程序包含一个绑定到托管 bean 属性的输入字段,并且有两个命令按钮:第一个是标准 JSF 按钮,第二个是 PrimeFaces 命令按钮。他们都调用了一个javascript方法,该方法增加了输入字段中的数字,并且(希望)发送了一个ajax请求以刷新bean属性,然后响应再次刷新该字段,并使用相同的数字。我的问题是,当我第一次按下 PrimeFaces 按钮时,它没有正确刷新数字,实际上它的值仍然是初始的 0。第二次单击后,一切正常,标准按钮不会出现此问题。我检查了(在 Chrome 中)第一个请求和以下请求之间的区别,我发现了以下内容:
第一个请求:
form:input:1
form_SUBMIT:1
javax.faces.partial.ajax:true
javax.faces.source:form:j_idt9
javax.faces.partial.execute:@all
javax.faces.partial.render:form:input
form:j_idt9:form:j_idt9
第二:
form:input:1
form_SUBMIT:1
javax.faces.View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RReX/DmCg==
javax.faces.partial.ajax:true
javax.faces.source:form:j_idt9
javax.faces.partial.execute:@all
javax.faces.partial.render:form:input
form:j_idt9:form:j_idt9
我们使用 Glassfish 3.1.2、PrimeFaces 3.2 和 Apache-MyFaces 2.0.2。
有人可以帮我吗?
烟雾三合会