Tuesday, September 13, 2016

Passing Parameters from Manage bean to JavaScript in af:resource tag

There are certain scenario where on button click you execute some logic and send parameter to JavaScript to perform some operation. If you ran into similar kind of scenario ,below is one of the way to implemented.

For this sample on button click JavaScript Function is invoked sending parameter to open a URL('www.google.com') in this case

//Execute some logic above
FacesContext facesContext = FacesContext.getCurrentInstance();
ExtendedRenderKitService service =
org.apache.myfaces.trinidad.util.Service.getRenderKitService(facesContext, ExtendedRenderKitService.class);

service.addScript(facesContext, "launchURL('" + "https://www.google.com/" + "');");

On the page resource tag is added and a function which accepts a parameter inside function window.open()  is called with the pararmeter send from bean




Happy Coding !!!

No comments:

Post a Comment