ShowTable of Contents
Developing traditional Domino Web pages, I often used a symple techinque to dynamically change options in a combobox, depending on a key typed in an input box. Through an Ajax call to a Lotus Script agent, I could use HTML code sent back to the browser by the "print" statement to populate my "<select>" options.
Applying the same technique to XPages it's maybe possible, but it looked to me quite tricky and not consistent with the XPages model. Thus, I started playing with events and Server Side JavaScript to find out a different solution.
The goal
A combo box in a web page shows by default a list of options from a Notes View.
Typing a word or a sentence into the input box, a user can refine the search and get a subset of the original list shown in the combobox.
What I needed was not Type Ahead. A user must be able to type a word or a sentence and have the system automatically look for documents containing such a word anywhere in a couple of fields.
The solution
1. The database must be indexed
2. The input box is binded to a Request Scope "nameToSearch"
3. The "on blur" event for the input box and/or the "on click" event for the button have a simple Action (Server Side JavaScript) coded as follows:
"sessionScope.nameToSearch = requestScope.nameToSearch" and the Server Option put to "Partial update" --> combobox ID
4. Values for combobox are computed (dynamically), through a server side JavaScript
var criteria = sessionScope.nameToSearch;
var searchKey = "([NomePunto] CONTAINS "+criteria+" OR [Città] CONTAINS "+criteria+" OR [CodicePV] CONTAINS "+criteria+")";
var currDoc:NotesDocument;
var myOpt=new Array();
if (null != criteria && criteria != ""){
var currDb:NotesDatabase = session.getCurrentDatabase();
var currView:NotesView = currDb.getView("(PuntiVendita)");
var viewElem = currView.FTSearch(searchKey);
if (viewElem >=1) {
for (i=1;i<=viewElem;i++) {
currDoc = currView.getNthDocument(i);
if (null != currDoc) {
myOpt[i-1]=currDoc.getItemValueString("NomePunto")+" - città: "+currDoc.getItemValueString("Città")+" - provincia: "+currDoc.getItemValueString("Provincia");
}
}
myOpt.sort();
}
else {
myOpt = "";
}
}
else {
myOpt = @DbLookup(@DbName(),"(PVComposti)",filtro,2);
myOpt.splice(0,0,"");
}
The code - step by step