maandag 25 januari 2016

Auto-refresh on table in ADF

For some people this will be a very basic thing to handle, but I had to google from different sources to get this to work, so maybe this be of use to someone else too ..

My requirement is to auto-refresh a table without having to press a button or do refresh. The refresh should not be triggered by another field in the form .. the table is showing status results which are refreshed automatically from the database or other events in our SOA process.

So how does this work?

1. First make sure your table is not set to caching otherwise the data you see in your page is old even if you refresh (Oracle ADF Web Browser Refresh button gets old page/data).

a. To do this go to your table and check the object it is referring to.
b. Now open the Bindings tab of your page and find the correct iterator for this object.
c. In the property inspector of the iterator you set CacheResults to false in the advanced tab.

If you use manually refresh now you get the new data.

2. Second, we are going to add an execute action as a binding to our page. Open the bindings page again and add a binding of type Action.
Navigate to the object in your application module that refers to the table and choose as operation Execute.

3. Go back to your page and in your components palet  choose Poll to add a polling element to your page. In the property inspector you can set the interval in milliseconds (so 10000 is 10secs).

4. Go to the property inspector of the poll and choose Edit on the PollListener (open it using the wheel and choose Edit). Create a new managed bean and a method. In my case I want to refresh the status so I choose refreshStatus. Your bean is the package and could be anything like MyBean, etc to group your methods. You don't have to keep them one to one of course.

You have to choose the package where you want to add your bean. You could use
for example to make sure all your beans are stored in the same place.

5. Modify the code for the bean as follows

public void refreshStatus (PollEvent pollEvent) {          
// Add event code here...                   
  BindingContainer bindings = (BindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();                OperationBinding operationBinding = (OperationBinding)bindings.getOperationBinding("Execute");                
 Object result = operationBinding.execute();       

And make sure you include the correct libraries

import oracle.adf.model.BindingContext;

import oracle.adf.model.OperationBinding;

import oracle.binding.BindingContainer;

import org.apache.myfaces.trinidad.event.PollEvent;

6. Now in the partial trigger of the poll element we choose Edit and shuttle the table to the right.

That should do the trick! The table refreshes every so many seconds without you having to refresh it yourself.