Wednesday 19 January 2011

Xpages - Combobox - set first choice to blank

In Xpages the combobox works different from what you are used to in the Notes form equivalent, the dialog list field.
In Notes if you get the choices using an @DbColumn or @DbLookup, assign no default value and the user does not consciously pick a value, no value is assigned to the field.
But when you do that with a combobox in Xpages, the first value in the list of choices will be assigned to the field.
Usually that is not what I want, I want the user to make a conscious choice. And assigning a default value of a space does not help if that value is not in the list of choices. So you will have to add a blank value as the first option in the list of choices.
I found 2 ways to solve this and it eliminates the need to set a default value.

1. The simplest way is to add a space as the first label-value pair and for the second add the rest of the choices using @DbColumn/@DbLookup.

2. Insert a blank value in the javascript code that retrieves the list of choices using @DbColumn/@DbLookup. This is probably the better method if you also want to include code to do some form of cache. See the code sample below.

 // get the cached result if used before 
var list = sessionScope.<cachename>;
// if no cached values found, create it
if (!list) {
// create an array with 1 blank entry as first entry
var arr = new Array(" ");
var res = @DbLookup("", "<a view>", "<a key>", 2);
// append the retrieved values to the array
var list = arr.concat(res);
sessionScope.<cachename> = list;
}
return list;

Tuesday 18 January 2011

Lotusphere 2011 agenda app for Android

For the Android adepts it is good to know that there is also a ls11 agenda app available. Search for "lotusphere" in the market and you will find the LS11 agenda app posted by Joseph Jaquinta based on the geniisoft version.
Dave Hay also mentions it on his blog.
As for the mix up of names. The app is written by Jo Grant (as Dave mentions), but appearantly posted in the market by Joseph Jaquinta.
It has a nice and simple layout and good options to filter and tag your favorite sessions.

thanx Jo !!

You will also find a LS11 app in the market from Sogeti, a game with a nice reward for the winner?!

Thursday 6 January 2011

Xpages and the failing Repeat control

I am converting an application to Xpages and use the repeat control to build several levels of dynamic menu structures.
They are based on simple @DbColumn and @DbLookup. But when the result array is only one entry the repeat control fails. The code below shows the failing repeat control (xp:link simplified to keep the code clean).
[Note: single results from @DbColumn or @DbLookup are returned as string and not an array.]
 <xp:repeat id="repeat1" rows="30" var="rowData" indexVar="rowIndex"> 
<xp:this.value><![CDATA[#{javascript:
@Unique(@DbLookup("", "xpSectionList", sessionScope.regionFilter, 2))
}]]></xp:this.value>
<li>
<xp:link escape="true" id="linkSubSection" title="#{javascript:rowData}">
<xp:this.text><![CDATA[#{javascript:rowData}]]></xp:this.text>
</xp:link>
</li>
</xp:repeat>
After some searching I found a solution in the LDD by Bob Cross, "Hint for Repeating a single value".
Repeat controls are great - but they MUST return an array, even if it is just one entry.

In my example, I used a repeat control to display entries from a dblookup. However, some of my lookups only returned one entry, so the result was a string, not an array. Since the result of my dblookup was a string, the repeat control would not display the one returned result.

The solution is to convert the result to a string first by using valueOf(). This returns a string delimited by commas. Then split the result by the commas to get an array. If split fails, then the result was an array to start with.

var tmpstr = result.valueOf();
try {
var newarr = tmpstr.split(",");
return(newarr)
}
catch(err){
return(tmpstr);
}
The proposed solution works fine and does solve the problem, but I consider it a workaround for a bug. The repeat control should also work when a single value is returned.
I have filed a service request (PMR) with IBM. Please do the same if you think this should be solved!
[Note: IBM have responded to the PMR: The repeat control works as designed and expects an array as input.]
The solution workaround is implemented in the code below.
 <xp:repeat id="repeat1" rows="30" var="rowData"  indexVar="rowIndex">
<xp:this.value><![CDATA[#{javascript:
var result = @Unique(@DbLookup("", "xpSectionList", sessionScope.regionFilter, 2));
var tmpstr = result.valueOf();
try {
var newarr = tmpstr.split(",");
return(newarr)
}
catch(err){
return(tmpstr);
}
}]]></xp:this.value>
<li>
<xp:link escape="true" id="linkSection" title="#{javascript:rowData}">
<xp:this.text><![CDATA[#{javascript:rowData}]]></xp:this.text>
</xp:link>
</li>
</xp:repeat>