

Cope with performance issue for complex master detail view in ADF
Have you ever experienced performance problems from complex master detail view with a lot of rows when trying to iterate through them and visualize data for the user? I am sure you have 🙂 In reality this is only compute time! However, can you imagine that such view can take more than 10 seconds to be iterated and visualized? This could cause a lot of complains and unhappiness from user point of view. In this blog I will show shortly how these 10 seconds could be reduced to a second. It’s 10 times faster!
Actual problem with complex master detail view
In this example I’ll firstly show how does the complex view with performance issue looks like. It’s the one we’ll improve later.
Here’s the view in the Application Module in our ADF Application:
The problem with the performance comes when we try to iterate this complex view in our jsff page. Below is a small snippet of the code to show how it looks:
For example if we have 10 rows for every view to be iterated this makes 10x10x10x10x10 = 100 000 iterations. In these views we have a lot of data and you can imagine how many iterations we have to make to visualize all the needed data from them.
Solution
The magic change is to use own data structure in the value of the iterator. The documentation of the component says:
“The specific model class is org.apache.myfaces.trinidad.model.CollectionModel. You may also use other model instances, e.g., java.Util.List, array and javax.faces.model.DataModel. The component will automatically convert the instance into a CollectionModel”.
So the first thing we should do is to make a new view and specify the query for it in a way that we can get all the needed data from it. Then we’ll store it in our data structure. All this should happen in the initialize method of the bean which is connected to the jsff page. After this is done, the view in the Application Module now is much simpler:
And the code in the jsff page now looks like that:
What you can see now in the value attributes of the iterators is that we are iterating over lists which are stored in the bean after executing the new view object. This way once you enter in the initialize method of the page, the view is executed and all the needed data is retrieved from it and stored in a data structure. This structure is adapted to keep the data on which we iterate in java.util.List collections. Now the opening of the page will take 1 second to load (in case of more data – 2 seconds as maximum), instead of more than 10 seconds which improves the performance to be about 10 times faster.
I hope this blog will help you to resolve such performance problems when you face them. Being a practical solution, the user was amazed after this fix. Feel free to add a comment and ask if something isn’t clear or share your ideas.