Defining data sources

An XPage can contain data sources based on Domino® forms and views.

The forms and views must already exist. See the Domino Designer Basic User Guide and Reference for descriptions and instructions.

The following XPage defines two data sources, one an existing form named main and the other an existing view named main. The var property assigns an identifier to access the data sources on the XPage.
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
	<xp:this.data>
		<xp:dominoDocument var="document1" formName="main"></xp:dominoDocument>
		<xp:dominoView var="view1" viewName="main"></xp:dominoView>
	</xp:this.data>
</xp:view>

See data - Data Source for a description of data sources and additional examples.

Defining data sources in Design mode

The XPages interface provides the following means for defining data sources:
  • When you create a new XPage, a dialog offers you the chance to add a data source.
  • The page or container properties can be adjusted to add, remove, and modify data sources. With focus outside all controls, click the Data tab under Properties.
  • The data palette can be used to add a data source. Open the data palette (Window > Show Eclipse Views > Data). A dropdown list contains the names of the existing data sources for the page or container plus the entry Define Data Source for adding new ones.

Form-based data sources

Form-based data sources are used by core controls such as edit boxes to bind the control to an item of data. With focus on the control, click the Data tab under Properties to specify the data source or define a new one. See Binding data elements for a description of the binding process.
By default, a data source creates a new document when an XPage is saved:
<xp:dominoDocument var="document1" formName="main"></xp:dominoDocument>
To have the data source replace an existing document, the action property must be specified:
<xp:dominoDocument var="document1" formName="main" action="editDocument"></xp:dominoDocument>

View-based data sources

View-based data sources are used by View controls.
An existing view on the data palette displays its columns. Selecting one or more columns and dragging them to the XPage creates a new View control containing those columns. In this example, the designer drags two columns from view2 to the XPage.
<xp:this.data>
	<xp:dominoView var="view2" viewName="main"></xp:dominoView>
</xp:this.data>
<xp:viewPanel value="#{view2}" id="viewPanel2">
	<xp:this.facets>
		<xp:pager partialRefresh="true" layout="Previous Group Next"
			xp:key="headerPager" id="pager2">
		</xp:pager>
	</xp:this.facets>
	<xp:viewColumn columnName="subject" id="viewColumn3">
		<xp:this.facets>
			<xp:viewColumnHeader value="Subject" xp:key="header"
				id="viewColumnHeader3">
			</xp:viewColumnHeader>
		</xp:this.facets>
	</xp:viewColumn>
	<xp:viewColumn columnName="$1" id="viewColumn4">
		<xp:this.facets>
			<xp:viewColumnHeader value="Last modified"
				xp:key="header" id="viewColumnHeader4">
			</xp:viewColumnHeader>
		</xp:this.facets>
	</xp:viewColumn>
</xp:viewPanel>
You can create a View control by dragging it from the controls palette (Window > Show Eclipse Views > Controls). In this case, you specify the Domino® view in the creation dialog and the definition of the dominoView becomes part of the viewPanel definition.
<xp:viewPanel rows="30" id="viewPanel1">
	<xp:this.facets>
	 <xp:pager partialRefresh="true" layout="Previous Group Next"
			xp:key="headerPager" id="pager1">
		</xp:pager>
	</xp:this.facets>
	<xp:this.data>
		<xp:dominoView var="view1" viewName="main"></xp:dominoView>
	</xp:this.data>
	<xp:viewColumn columnName="subject" id="viewColumn1"
		<xp:viewColumnHeader value="subject"
			id="viewColumnHeader1">
		</xp:viewColumnHeader>
	</xp:viewColumn>
	<xp:viewColumn columnName="$1" id="viewColumn2">
		<xp:viewColumnHeader value="last modified"
			id="viewColumnHeader2">
		</xp:viewColumnHeader>
	</xp:viewColumn>
</xp:viewPanel>

You can modify a view column. Put the column in focus and select the Data tab. You can change the binding or the display type. You can compute the value of the column rather than binding it to a Domino® view column. You can also redefine a column by dragging an element from the data palette into the column.

To add a column, right-click the View control and specify Insert Column or Append Column. You can the specify the content of the new column by dragging from the data palette or specifying it on the dropdown menu on the Data tab.

All columns in a view must have the same view source.