How to use EL in PrimeFaces oncomplete attribute that gets updated during method action

This is the code:

 <p:ajax event="eventResized" process="@this calendar"  listener="#{bean.eventResized}" oncomplete="resizeComplete()"/>

      

eventReized

, called EventResizeBehavior

, which propagates from AjaxBehaviorEvent

and contains some property. Can I check inside the <p:ajax....>

call to its value and pass the result tooncomplete="resizeComplete(result)"

Something like that

<p:ajax event="eventResized" process="@this calendar"  listener="#{bean.eventResized}" oncomplete="resizeComplete(#{eventResized.id == 0})"/>

      

+3


source to share


1 answer


PrimeFaces doesn't support it. Any EL expressions in the attribute are oncomplete

immediately evaluated during the response of that HTML document, not during an incomplete associated ajax call. Basically, the JavaScript code generated by the attribute oncomplete

contains the old value as it did when the page was loaded.

Best used RequestContext#addCallbackParam()

to add a property to a args

PrimeFaces target that is available in oncomplete

scope.

RequestContext.getCurrentInstance().addCallbackParam("result", eventResized.getId() == 0);

      



<p:ajax ... oncomplete="resizeComplete(args.result)" />

      

An alternative is to use RequestContext#execute()

instead oncomplete

to programmatically instruct PrimeFaces to execute a chunk of JavaScript upon completion of the ajax.

RequestContext.getCurrentInstance().execute("resizeComplete(" + (eventResized.getId() == 0) + ")");

      

+5


source







All Articles