问题描述
这是代码:
<p:ajax event="eventResized" process="@this calendar" listener="#{bean.eventResized}" oncomplete="resizeComplete()"/>
eventReized
由 EventResizeBehavior
调用,它从 AjaxBehaviorEvent
扩展而来,它包含一些属性.我可以检查内部 <p:ajax....>
调用它的值并将结果传递给 oncomplete="resizeComplete(result)"
eventReized
invoked by EventResizeBehavior
which extended from AjaxBehaviorEvent
and it contains some property. Can I check inside <p:ajax....>
call its value and pass result to oncomplete="resizeComplete(result)"
类似的东西
<p:ajax event="eventResized" process="@this calendar" listener="#{bean.eventResized}" oncomplete="resizeComplete(#{eventResized.id == 0})"/>
推荐答案
PrimeFaces 不支持它.oncomplete
属性中的任何 EL 表达式都会在该 HTML 文档的呈现响应期间立即计算,而不是在关联的 ajax 调用的 oncomplete 期间.基本上,由 oncomplete
属性生成的 JavaScript 代码包含页面加载期间的旧值.
PrimeFaces doesn't support it. Any EL expressions in oncomplete
attribute are immediately evaluated during render response of that HTML document, not during oncomplete of the associated ajax call. Basically, the JavaScript code generated by oncomplete
attribute contains the old value as it was during the page load.
您最好的选择是使用 RequestContext#addCallbackParam()
将属性添加到 PrimeFaces 特定的 args
对象,该对象可在 oncomplete
范围.
Your best bet is using RequestContext#addCallbackParam()
to add a property to the PrimeFaces-specific args
object which is available in oncomplete
scope.
RequestContext.getCurrentInstance().addCallbackParam("result", eventResized.getId() == 0);
<p:ajax ... oncomplete="resizeComplete(args.result)" />
另一种方法是使用 RequestContext#execute()
而不是 oncomplete
以编程方式指示 PrimeFaces 在完成 ajax 请求时执行一段 JavaScript.
An alternative is to use RequestContext#execute()
instead of oncomplete
to programmatically instruct PrimeFaces to execute a piece of JavaScript on complete of the ajax request.
RequestContext.getCurrentInstance().execute("resizeComplete(" + (eventResized.getId() == 0) + ")");
这篇关于如何在操作方法期间更新的 PrimeFaces oncomplete 属性中使用 EL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!