Search code examples
javaxpages

sharing computation between repeat control data-binding and row property


For an xp:repeat control I compute the data-binding via a managed bean which contains a list of java objects in it. e.g.

employeeBean.loadList(key);
return employeeBean.profiles;

the first line will set the profiles field on the bean which will contain an arraylist with profile objects.

In some cases the customer does not want to have a pager control so I calculate the number of rows as followed:

employeeBean.loadList(key);
var coll = employeeBean.profiles;
return coll.length;

I notice I am calling the same method two times while I have the data already in the first call.

How can I share the data between the data-binding computation and the row property computation?


Solution

  • Everything depends on loadList() implementation. Make it optimal to be called many times and you are fine. Just hold your list in some internal property of the bean and use cache:

    if (property == null) {
      property = getListData();
    }
    return property;
    

    Work with scope, request or view should be fine. In case your list contains Domino native objects, stick to request only.