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!

How to create a spotlight page for your Notes database

To maintain the development of a number of standardized applications I use a Notes database where developers/application owners can register ‘new ideas’ for applications, convert them into tasks and include them in planned releases.

One application for example allows the storage of all kinds of documents, define a review cycle, set access restriction et cetera. To offer a more attractive ‘startpage’ that will make it easier for users to scan new contributions or their own latests contributions the idea of a ‘spotlight‘ emerged:

Basically we created a form that will be opened within a classical frameset when launching the application.

Form requirements

SaveOptions field, set to “0” and hidden ofcourse.

Now for each ‘entry’ I have 7 hidden fields:

Tx_TitleSpotDoc1, text, editable

Na_AuthorSpotDoc1, names, editable

Td_ModifiedSpotDoc1, date/time, editable

Tx_ReadableDateSpotDoc1, text, editable

Tx_FileTypeSpotDoc1, text, editable

Tx_FileTypeIconSpotDoc1,text, editable

Tx_UNIDSpotDoc1, text, editable

(for the next entries the fields are called Tx_TitleSpotDoc2, Tx_TitleSpotDoc3 etcetera)

For the entries under the ‘My Latest Documents’ header the fields are named:

Tx_TitleMySpotDoc1, text, editable

Na_AuthorMySpotDoc1, names, editable

Td_ModifiedMySpotDoc1, date/time, editable

Tx_ReadableDateMySpotDoc1, text, editable

Tx_FileTypeMySpotDoc1, text, editable

Tx_FileTypeIconMySpotDoc1,text, editable

Tx_UNIDSpotMyDoc1, text, editable

In the part where I diplay the entries the markup looks like this:

Note that all fields are computed for display.  Here are their values:

Computed image: @Text(Tx_FileTypeIconSpotDoc1)

Title: Tx_TitleSpotDoc1

Author: @Name([CN]; Na_AuthorSpotDoc1)

Modified: Td_ModifiedSpotDoc2

Added: Tx_ReadableDateSpotDoc1

The computed image and the title field have an Action Hotspot, with the onclick value:

Sub Click(Source As Button)
Dim ws As New NotesUIWorkspace
Call OpenDocumentByUNID(ws.CurrentDocument.Document.Tx_UNIDSpotDoc1(0))
End Sub

They also use a Script Library (LotusScript):

Use “StartPageFunctions”

The form has also this library referenced under (Options).

Under the Postopen event we call the initiation function:

Sub Postopen(Source As Notesuidocument)
Call StartPageInit(Source)
End Sub

I will include the script as a file: startpagefunction.dxl

That’s about it! Now you have a much more interesting startpage for your Notes app!

Here are the icons used: