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:this.dataContexts>
<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 );
}]]></xp:this.value>
</xp:dataContext>
</xp:this.dataContexts>
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!



After an x number of years working in the same environment I have decided to look for a new challenge. Are you looking for a smart companion?

Ian Mannion said
Looks good and could think of many uses for this! Tip of the day, Did you know…
Patrick Kwinten said
exactly!