Category Archives: Lotus Notes

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.

XPages: Rendered Vs Loaded

Today I observed runtime error in one of my XPage. I investigated later and found that the error is occuring on a custom control which should not be rendered in this scenario. I have several custom controls added on my XPage and display only one custom control based on some condition, so I have computed the rendered property.
Now the question is, if the custom control is not rendered then why it is generating error?
I further investigated properties of the custom control and found there is a property “loaded”.

Rendered: it controls the visibility of the control, i.e., if it is true then the markup for this control will be added in the response.

Loaded: it controls the creation of control, i.e., if it is true then only the control is going to be created else it will not be created.

Coming to my problem, I moved my code from rendered to loaded property and everything is working fine. The custom control is not being created so there is no possibility of execution of any code inside that custom control.

Get list of XPages

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