Execute Javascript code from Java Code

In ADF framework you can execute Javascript code from Java code using the below method

   public static void runJavaScriptCode(String javascriptCode) {  
     FacesContext facesCtx = FacesContext.getCurrentInstance();  
     ExtendedRenderKitService service = Service.getRenderKitService(facesCtx, ExtendedRenderKitService.class);  
     service.addScript(facesCtx, javascriptCode);  

Import the following classes
 import javax.faces.context.FacesContext;  
 import org.apache.myfaces.trinidad.render.ExtendedRenderKitService;  
 import org.apache.myfaces.trinidad.util.Service;  

You can call previous method from anywhere from your code
For example I will display alert using javascript
 runJavaScriptCode("alert(\"My name is Mahmoud\");");  


Popular posts from this blog

ADF : Get Current Logged User Name

OAF : Get Current Row in Table

ADF : Working with ViewCriteria