Learning XPages Part 40 : Two Data Sources One Xpage

Now that we have a nice pager on top of
table showing all the people at a single location wouldn’t it be nice to
display some of information found in the location document like the location’s
address and main numbers?

In XPages you are not restricted to
a single source for your data. At the moment we have a data source on the
location XPage that is associated with the categorized people view in our
notes database. In this part I’m going to create a new data source that
is associated with the location document. Lets start by opening the content_Location
custom control and looking at the pages properties go to the data section.

In here you should see the data source
called ‘peopleView’ that we defined earlier in the series. Let’s click
on the Add button and select a Domino Document. I’m going to call mine
‘locationDoc’ and base it on the ‘location’ form that is in the current
database. We also need to tell the data source the Document ID of the document
we are going to be referencing.

A picture named M2

There are a couple of ways to tell the
data source what Document ID you want to work with. I’ve decided I’m going
to use the sessionScope variable called locationfilter and look up the
document in a view.

var locView:NotesView = database.getView("lkp_Locations");
var locDoc:NotesDocument = locView.getDocumentByKey(sessionScope.locationfilter);

return locDoc.getUniversalID()

In this code I create a variable called
locView and set it to the lkp_Locations view in the current database. I
then create a second variable called locDoc and I do a simple NotesView.getDocumentByKey
to look up the document using the sessionScope variable. I then return
that documents Universal ID. As you can see this code, even though it is
JavaScript is more similar to LotusScript then anything else.

Now that I have my Data Source I can
start creating fields and labels on my custom control. Don;t forget you
can use the data pane on the right of your screen to quickly get the field
names that you have used in this document :

A picture named M3

Here’s what the design view of my content_location
custom control looks like after I dragging in some data fields

A picture named M4

And now if I preview this in my web
browser you can see my test data appearing.

A picture named M5

And that’s it, in a couple of very easy
steps we are able to have two different data sources on a single XPage.
In this case they were a view and a document but there is nothing stopping
you from having two or more views or any mix of views and documents that
you need for your application.

Tagged with: , ,
Posted in None
3 comments on “Learning XPages Part 40 : Two Data Sources One Xpage
  1. Brendan says:

    Something I found when dealing with multiple documents on one page was that if you try to use simple actions in buttons, etc, they affect only the last document listed.If you were to have two documents on the XPage and you have a button called “Edit” that has a simple action of “change document mode” to “edit” only the second document will be opened in edit mode.


  2. hflag says:

    the source code on openntf


  3. hflag says:

    the source code on openntf


Comments are closed.

%d bloggers like this: