我对轮询组件有一个奇怪的问题(可能是一个错误),并试图在回调时返回值。因为 Poll 元素在调用的“oncomplete”函数上返回 undefined。
我不明白为什么 args 总是未定义。我都试过了。日志总是说未定义的 args 参数。
这似乎是“poll”元素的问题,因为如果我使用“commandButton”一切正常并且args返回是正确的......为什么?
Mojarra 2.2.8、PrimeFaces 5.2、Tomcat 7
这是我的 dash.jsf:
<h:form>
<p:poll actionListener="#{markersView.save}" oncomplete="handlePollRequestComplete(xhr, status, args)" widgetVar="mypoll" />
</h:form>
<script>
function handlePollRequestComplete(xhr, status, args) {
PrimeFaces.debug("Save:" + args.saved);
}
</script>
MarkersView.java:
import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import org.primefaces.context.RequestContext;
import org.primefaces.model.map.DefaultMapModel;
import org.primefaces.model.map.LatLng;
import org.primefaces.model.map.MapModel;
import org.primefaces.model.map.Marker;
@ManagedBean
public class MarkersView {
private MapModel simpleModel;
@PostConstruct
public void init() {
}
public void save() {
RequestContext context = RequestContext.getCurrentInstance();
context.addCallbackParam("saved", "true"); //basic parameter
}
}
记录 PrimeFaces:
20/6/2015, 11:07:25 : Initiating ajax request.
20/6/2015, 11:07:25 : Form to post j_idt12.
20/6/2015, 11:07:25 : URL to post /dash.jsf.
20/6/2015, 11:07:25 : Post Data:javax.faces.partial.ajax=true&javax.faces.source=j_idt12%3Aj_idt13&javax.faces.partial.execute=%40all&j_idt12%3Aj_idt13=j_idt12%3Aj_idt13&j_idt12=j_idt12&javax.faces.ViewState=6291534270084680507%3A9051076211686237374
20/6/2015, 11:07:25 : Response received succesfully.
20/6/2015, 11:07:25 : DOM is updated.
20/6/2015, 11:07:25 : Save:undefined
20/6/2015, 11:07:25 : Response completed.
响应日志:
<?xml version='1.0' encoding='UTF-8'?>
<partial-response id="j_id1"><changes><update id="j_id1:javax.faces.ViewState:0"><![CDATA[1663230282338470443:-2846533344041645415]]></update></changes></partial-response>