Discover full tutorial here : https://cedricleruth.com/how-to-execute-client-javascript-in-an-adf-java-bean-action/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*** In YOURJSF.jsf button, or other component that need to execute a javascript on action, add : ****/ | |
<af:commandButton text="ClickMe" id="cb1" actionListener="#{YOURSCOPE.YOURJAVABEAN.clickToExecuteJavascriptAction}"/> | |
/*** In YOURJAVABEAN.java class add : ***/ | |
public void clickToExecuteJavascriptAction(ActionEvent actionEvent) { | |
this.executeClientJavascript("console.log('You just clicked : " + actionEvent.getSource() + " ')"); | |
//Note: if you use a java string value in this function you should escape it to avoid breaking the javascript. | |
//Like this : stringValue.replaceAll("[^\\p{L}\\p{Z}]", " ") | |
} | |
//You should put this function in a util java class if you want to use it in multiple bean | |
public static void executeClientJavascript(String script) { | |
FacesContext facesContext = FacesContext.getCurrentInstance(); | |
ExtendedRenderKitService service = Service.getRenderKitService(facesContext, ExtendedRenderKitService.class); | |
service.addScript(facesContext, script); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment