Wednesday, 9 January 2013

Calling Javascript method using java in ADF

While working in my project I came to a situation in which I have to make a call to a JavaScript method, on load of the page. The JavaScript method was taking a parameter as an input and the value of the parameter has to come from java class.

Let's find the solution in the below example : 

1.  Create a sample jsff page and write a JavaScript method inside it. E.g "homeLoad.jsff" containing a JavaScript method as "myMethod(args)"

2. Create a Class and Java method such as "onLoadOfPage()", which will contain the code to call a JavaScript method and passing a parameter.

3. Create a taskflow such as "myTF.xml" and use Java method as default activity and jsff as an outcome.

4. Now, finally create a jspx page as "Home.jspx" and use taskflow as a region. Run the page.

Output :

*Comments and feedback are most welcomed, Thanks.


  1. Thanks a lot gopal.It will help me in my project work.
    Excellent post!!!

  2. Crisp and Clear Bro. :)

  3. How to get the value the JS method returns?

  4. Diego,
    You can try a af:serverListener and invoke it from javascript and get the value you are looking for in java.

    function getDataUsingJS(event){
    var component = event.getSource();
    AdfCustomEvent.queue(data, "myMethod", {scriptValue:'Test Data'} ,false);

    Method in a bean :

    public void getValueFromJS(ClientEvent clientEvent) {

  5. Thank you for this publication.

    Best regards.