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!

About these ads

Born in Holland, current country of residence is Sweden. IBM Notes Consultant since 1997. Main focus is Xpages development. Other interests: computers, motorcycles, music (bass guitar) & cooking.

Tagged with: , , ,
Posted in XPages
2 comments on “Spotlight function – Binding a panel to a datasource
  1. Ian Mannion says:

    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

Introduction
I am Patrick Kwinten. I am a IBM Notes Domino Product Specialist since 1996. With this blog I am trying to give my contribution to the community.
.
The posts in this blog project my personal opinions, not the company I work for.
CV
OpenNTF
Follow my projects on OpenNTF. Below are some examples:

Categories
RSS Feed
Follow

Get every new post delivered to your Inbox.

Join 222 other followers

%d bloggers like this: