Binding data elements

XPages controls can be bound to elements of data sources.

Once a Domino® Document data source is defined, you have access to its items. You can bind these items to controls. This means that data entered into the control by the user is assigned to the bound item when the document is saved. Likewise when a document is retrieved, the value of an item is assigned to the bound control. In Source mode, a bound item takes the form of an EL expression starting with the name of the data source. Here an input box is bound to the subject item of the document1 data source.
<xp:inputText value="#{document1.subject}" id="inputText1"></xp:inputText>
Controls can also be bound to global variables and the return values of scripts.

Data palette

Data sources and their constituent items can be seen on the data palette (Window > Show Eclipse Views > Data). You can drag and drop data items onto the XPage. If a control already exists, dragging a data item into it binds the control to the item. For example, if you have the following unbound edit box:
<xp:inputText id="inputText1"></xp:inputText>
Dragging in the subject item from document1 yields:
<xp:inputText id="inputText1" value="#{document1.subject}"></xp:inputText>
If you drag a data item onto the XPage proper (outside all controls), an appropriate context is created. For example, dragging the subject item from document1 onto the XPage proper yields:
<xp:table>
	<xp:tr>	<xp:td>
		<xp:label value="Subject:" id="subject_Label1" for="subject1"></xp:label>
	</xp:td><xp:td>
		<xp:inputText value="#{document1.subject}" id="subject1"></xp:inputText>
	</xp:td></xp:tr>
</xp:table>
An input box is set up in column 2 of a table with a label in column 1.
The data palette contains a Select Controls dialog box toggle switch in the upper left. By default it is disabled. If you enable it (by clicking it), you are presented with a dialog when you drag a data item onto the XPage. The dialog permits you to:
  • Change the type of control.
  • Add a Button control of type Submit.
  • Add a Display Errors control

Data tab

A binding mechanism exists on the Data tab for controls that can be bound to Domino® document items. A dropdown menu allows you to select or create the data source. Another dropdown menu allows you to select the item. Elsewhere you can verify the display type and format, and provide a default value.
In the following example, focus is on an Input Box control. The user selects the Data tab, selects document1 and number from the dropdown menus, verifies that the display type is Number, and provides a default value.
<xp:inputText id="inputText2" value="#{document1.number}" defaultValue="1">
	<xp:this.converter>
		<xp:convertNumber type="number"></xp:convertNumber>
	</xp:this.converter>
</xp:inputText>