Skip to main content link. Accesskey S

XPages Wiki

Submit Search

YouAtNotes XPages Wiki


Home > Server JavaScript > Work with datasources

Work with datasources

ShowTable of Contents

Where to define a datasource


You can define a datasource on different levels:
  • in the XPage properties
  • in the properties of a custom component
  • in the properties of a panel


Use the folowing rule of thumb:

If you need a datasource in your whole XPage and even in custom components which are included on your XPage, then define the datasource in the XPage properties.
If you need a datasource only inside a custom component, define it in the properties of that component.
If you need to have multiple datasources on one XPage, wrap all logic which works with one datasource inside a panel, and define the datasource in the panel's properties.

The default datasource object


If you just have one document datasource on your page, you can use

currentDocument


to access it. That is handy if you want to work with that datasource in customer controls, too.
Don't use it if you have multiple datasources on your XPage.

Working with multiple datasources on one page


You can have mutiple document datasources on one page, and you can save/submit all of them by different buttons at different types. But to do that, you need some tricks.
First, don't set the type of a save button to "submit". A "submit" button ALWAYS submits ALL datasources at once. Regardless if they are defined in the XPage, component or panel properties.

This problem was solved by Jeremy Hodge which wrote an excellent article in the XPages Blog here: http://xpagesblog.com/xpages-blog/2009/8/18/saving-one-out-of-many-data-sources-on-an-xpage-and-how-to-c.html?lastPage=true#comment5154816.

In short, you need to to this:

1.) Create panels, and define each datasource in one panel's properties.

2.) Put your "save" button inside the panel. Put all fields related to that document source into that panel, too.

3.) Set the button to type "button", set the onclick event to "simple action" with the action "save document".

4.) Add another simple action to the onclick event of the button: Execute script, with a server side javascript to clear all fields after saving the document like this:

datasourcename.replaceItemValue("fieldname", "")


5.) In the panel properties, go to "all properties" -> data -> data -> dominoDocument -> scope and set that to "request".
This allows that after saving the document a NEW document is created and represented by the datasource.

Mutiple datasources on one page with different edit mode


See Steves Blog for details.

In short: you can make a datasource's editmode independent of the request/URL parameters by setting all properties -> data -> datasource -> ingoreRequestParams = true.

With that, you can have for example one datasource in read mode, and other datasources in edit mode on the same page.

Pass a datasource as parameter to a custom control


Create a new custom parameter in your custom control, use the type "Data Sources/DocumentDataSource" (click on the folder button next to the type field).
Go to "All properties" In the custom control's property in your XPage, locate your property, click on the diamond enter a computed value, enter for examle "# mydoc" if your datasource is named "mydoc".

See Designer Wiki for details.
See what's possible with Xpages.
Have a look at our ServiceCommunicator website
and the YouAtNotes Support.
Use  searchlotus.com  for news in the Web related to Lotus Notes and Domino,
and to search those sites.
Check  youatnotes.com  for great Lotus Notes, Domino and XPages software.
Did this wiki help you?
Did this saved you time? Express your gratitude by making a donation:
PayPal - The safer, easier way to pay online!