0

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);
}

1 Answer 1

1

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)"/>
Sign up to request clarification or add additional context in comments.

1 Comment

oncomplete is the right attribute, but not sure if xhr is a known js variable in that moment (similar for other parameters).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.