Sunday, May 29, 2011

How to execute Javascript in Java in Oracle ADF

Hi,

A quick code snippet how to execute Javascript in java in Oracle ADF.



import javax.faces.context.FacesContext;
import org.apache.myfaces.trinidad.render.ExtendedRenderKitService;
import org.apache.myfaces.trinidad.util.Service;
.......
.

FacesContext fctx = FacesContext.getCurrentInstance();
ExtendedRenderKitService erks =
Service.getRenderKitService(fctx, ExtendedRenderKitService.class);
String myJavaScriptCode = "alert( "+"Hello World"+");";
erks.addScript(fctx, myJavaScriptCode );



Have a nice day,
Zeeshan Baig

3 comments:

  1. hi,
    How to call existing JavaScript function that take an Arguments.

    I want to pass some variables from the Bean to to a JavaScript function that take an arguments.

    ReplyDelete
    Replies
    1. Hi,

      You need to add af:resource tag to include java script on your page then call in a similar way

      af resource tag http://www.baigzeeshan.com/2011/05/how-to-load-javascript-and-css-files.html

      Check this whitepaper as well http://www.oracle.com/technetwork/developer-tools/jdev/1-2011-javascript-302460.pdf

      Hope it helps,
      Zeeshan

      Delete