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: http://java.sun.com/javase/6/docs/api/java/util/TreeMap.html
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.

Lesson: Never Try to Justify

A a very beautiful story!! about Imam Al-Shafi’ie ..

While Imam Shafi’i was sitting with his students, a maid came to him and said : “O Imam ! how come you fornicate by night and then turn to a preacher by day ?!!”

The students of Imam Shafi’ looked at him waiting for him to deny her claim. The Imam just looked at her and told her :”how much do you want me to pay you (as a wage for that night)?”
His students became so furious; some of them started to yell, others stood up to leave the room.

The Imam told them:”consider me as a date which you eat its good part and then throw away its stone.”
The students didn’t like what he said.

Suddenly, a man came running to the maid telling her:”Your house is on fire and all your children are inside of it!”
All of them, including Ash-Shafi’i, run to the burning house. The Imam entered the house quickly and saved the children.

At that point, the maid confessed with a broken spirit:”the Jewish made me accuse you falsely to ruin your reputation in front of your students”
The students of the Imam looked at him wondering about the reason which stopped him from defending himself in front of them.

Ash-Shafi’I said:”If I had denied the accusation, you would have split into 2 groups : a group which would not believe me and another one which would believe me but would continue to have doubts about me. So, I just wanted to entrust all my affair to Allah!

*Lesson taken from that : when you are falsely accused, never try to justify yourself too much to people no matter how oppressed and wronged you felt. Entrust all your affairs to Allah because HE is The Knower of what is hidden from people..