oko
oko

Reputation: 1355

Sending bean data to javascript method

I am trying to pass bean values to javascript code after ajax update but it doesn't work.

 <p:commandButton action="#{bean.transactionStarted}" onclick="userclicked(xhr,args,status)"/>

And the backing bean adds the value via:

RequestContext.getCurrentInstance().addCallbackParam("message", "message");

When I debug I am seeing upper statement executed correctly but it does not arrive to js and it is not alerting:

function userclicked(xhr, status, args) {
    alert(args.message);
}

Upvotes: 0

Views: 135

Answers (1)

Bjorn vleminckx
Bjorn vleminckx

Reputation: 26

Because onclick was called before backing bean method completed. You should wait until it finishes. Use oncomplete, as follows:

<p:commandButton action="#{bean.transactionStarted}" oncomplete="userclicked(xhr,args,status)"/>

Upvotes: 1

Related Questions