There are many ways to execute some code before loading the page in adf.
They are:
1. By using Method activity in the Task flow.
We can achieve this in 2 ways again.
a. Add the code to be executed, to a method in ApplicationModuleImpl class and expose it to client interface. From Data Control panel drag and drop that method to the Task flow. In the task flow add the page (view activity) and navigation from the method activity to the view acitvity. In this approach, first the method will be invoked before rendering the page.
b. Add the code to be executed to the managed bean and add a method call activity to the Task flow. For that method call activity bind the method in the Managed bean. Now add the view activity(page) and add navigation from method call activity to the view activity. In this approach, first the method from the managed bean will be invoked before rendering the page.
2. Using invokeAction executables.
This approach is used when we dont want to use taskflow method call to execute this page load code. If we dont have any task flows in our application and we are using only jsf pages, then this is the best approach. Add the code to the method in the ApplicationModuleImpl class and expose it to the client interface. Go to the pagedef file corresponding to the page and in the bindings section add the method from datacontrol. Now in the executables section add invokeAction executable. It will ask for some id and in the binds field specify the method action added in the bindings. Select the executabel now and go to Property Inspector. In the Refresh property specify “renderModel”. Now it will be executed before the page loads.
3. Using Server and ClientListener code
In the jspx page give the code in the following manner.
af:document id=”d1″
af:serverListener type=”onloadEvent”
method=”#{managedbean name.method name}”
af:clientListener method=”onLoadClient” type=”load”
af:resource type=”javascript”
function onLoadClient(event) {
AdfCustomEvent.queue(event.getSource(),”onloadEvent”,{},false);
return true;
}
af:resource
Source: http://adfnbpel.wordpress.com/2012/08/07/execute-some-code-when-the-page-loads-in-adf/
They are:
1. By using Method activity in the Task flow.
We can achieve this in 2 ways again.
a. Add the code to be executed, to a method in ApplicationModuleImpl class and expose it to client interface. From Data Control panel drag and drop that method to the Task flow. In the task flow add the page (view activity) and navigation from the method activity to the view acitvity. In this approach, first the method will be invoked before rendering the page.
b. Add the code to be executed to the managed bean and add a method call activity to the Task flow. For that method call activity bind the method in the Managed bean. Now add the view activity(page) and add navigation from method call activity to the view activity. In this approach, first the method from the managed bean will be invoked before rendering the page.
2. Using invokeAction executables.
This approach is used when we dont want to use taskflow method call to execute this page load code. If we dont have any task flows in our application and we are using only jsf pages, then this is the best approach. Add the code to the method in the ApplicationModuleImpl class and expose it to the client interface. Go to the pagedef file corresponding to the page and in the bindings section add the method from datacontrol. Now in the executables section add invokeAction executable. It will ask for some id and in the binds field specify the method action added in the bindings. Select the executabel now and go to Property Inspector. In the Refresh property specify “renderModel”. Now it will be executed before the page loads.
3. Using Server and ClientListener code
In the jspx page give the code in the following manner.
af:document id=”d1″
af:serverListener type=”onloadEvent”
method=”#{managedbean name.method name}”
af:clientListener method=”onLoadClient” type=”load”
af:resource type=”javascript”
function onLoadClient(event) {
AdfCustomEvent.queue(event.getSource(),”onloadEvent”,{},false);
return true;
}
af:resource
Source: http://adfnbpel.wordpress.com/2012/08/07/execute-some-code-when-the-page-loads-in-adf/