03 October, 2012

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\");");  

Thanks

No comments:

Post a Comment

ADF : Scope Variables

Oracle ADF uses many variables and each variable has a scope. There are five scopes in ADF (Application, Request, Session, View and PageFl...