Monday, May 26, 2014

How to invoke javascript from Managed Bean in PrimeFaces

In PrimeFaces, we can invoke a javascript function from managed bean.
One of the good example is to keep dialog open when validation exception.

Besides, other javascript function can be called.
code in xhtml

<p:commandButton value="Call JS from MB" action="#{myBean.callJsFromMB}" />

code in managed bean

public void callJsFromMB() {
    // other business logic or validation
    RequestContext.getCurrentInstance().execute("alert('test')");
}


Done!!

No comments:

Post a Comment

LinkWithin

Related Posts Plugin for WordPress, Blogger...