Spotlight function – Binding a panel to a datasource

This post is related to a question I posted on the XPages forum.

For my Bildr app I wanted to create a ‘spotlight area’ on the homepage where an individual image would get highlighted. The image would be randomly selected. I experienced some problems with the view control and repeat control. The question I received from Mark Leusing does exactly what I wanted the function to behave.

Since the solution is so simple I though re-sharing it with some more explanation would be benefitial for all new xpages developers…

First here is what the end result could look like:

In Designer I created a custom control and it’s structure is like this:

One of the panels (the ‘upper’ panel which contains panels with fields, links and computed text items in them) I have connected to a datasource called docRandom:


The setup for the data connection (dataContext) is as followed:

<xp:dataContext var=”docRandom”>
<xp:this.value><![CDATA[#{javascript:var vw:NotesView = database.getView(“$v-pixbyid”);
var numEntries = vw.getEntryCount();
var randomIndex = @Integer( (numEntries-1) * @Random() + 1 );

vw.getNthDocument( randomIndex );

Here I bind to a NotesView and randomly pick a document from that view via the vw.getNthDocument command.

From there I can use docRandom in my fields, links etcetera to collect the data I am interested in.


For those who are already enjoying their weekend I salute!