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: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!

2 thoughts on “Spotlight function – Binding a panel to a datasource

  1. Ian Mannion 2011-March-18 / 5:56 pm

    Looks good and could think of many uses for this! Tip of the day, Did you know…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s