Category Archives: XPages

XPage : Dynamic field Binding

In my application I wanted to bind a viewScope variable with the field, but the key was not static. The viewScope key was generated based on some business logic. To solve this problem, I created a dataContext variable (whose name is constant) and computed the value of this (data context) variable. I wrote the code there to calculate the key name. Finally I binded the field with the viewScope variable as follows:

The dataContext variable:

The field binding:

Same technique can be extended to other objects like NotesDocument, NotesViewEntry, etc.

XPage – Sort View Column – Optimized

In my previous post I discussed about sorting a view column using java.util.TreeMap. In this post I shall discuss about some optimizations to address the issue with duplicate values (refer to the line 19-21 in previous post).

Let us calculate time complexity of existing code:

From here:
This implementation provides guaranteed log(n) time cost for the containsKey, get, put and remove operations. Therefore,

Time complexity of TreeMap.containsKey, T1 = log(n)

Time complexity of TreeMap.put, T2 = log(n)

Time complexity of inner while loop, T3 = n * T1

Total time complexity,
T = n * (T3 + log(n)) log(n) for TreeMap.put
T = n * (n * T1 + log(n))
T = n * (n * log(n) + log(n))
T = n * (n + 1) * log(n)

From above calculation we can hardly do anything with T1 and T2, but we can optimize T3.

Let us modify the code to optimize:

From the API doc of HashMap:
This implementation provides constant-time performance for the basic operations (get and put), assuming the hash function disperses the elements properly among the buckets.

Let us calculate the time complexity of this code:

Time complexity of HashMap.containsKey, T4 = K1 , where K is constant

Time complexity of HashMap.get, T5 = K2 , where K2 is constant

Time complexity of HashMap.put, T6 = K3 , where K3 is constant

Total time complexity,
T’ = n * (T4 + T5 + T6 + log(n))
T’ = n * (K1 + K2 + K3 + log(n))
T’ = n * (K + log(n)) , where K = K1 + K2 + K3

It is clear that T’ < T. Hence our new algorithm is much more better than previous one.

How to know validation of which control is getting failed

Sometimes in XPage applications it happens that our code do not run due to validation errors.
It becomes really difficult to debug if the form contains too many fields. To simplify the debug process in this scenario I have written a code snippet which gives client id of the control for which validation is getting failed.

Get list of XPages

Following code will return the list of all XPages available in the specified database: