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.
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.
Thanks a lot gopal.It will help me in my project work.
ReplyDeleteExcellent post!!!
Crisp and Clear Bro. :)
ReplyDeleteHow to get the value the JS method returns?
ReplyDeleteDiego,
ReplyDeleteYou 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) {
System.out.println("Entering");
System.out.println(clientEvent.getParameters().get("scriptValue"));
}
Thank you for this publication.
ReplyDeleteBest regards.