In a previous article I explained how you can use the undocumented currentDocument data source
object to get the data source for the XPage from a Custom Control. This works great if the XPage has one data source. What if you have multiple data sources? For example, you want to include a custom control within a repeat control that is accessing multiple documents from a document collection or a view. The currentDocument variable would only point to the first data source on the XPage.
But, if you click on the folder icon next to the Type field you will see an extended list of type available.
*updated - see note below
Binding fields on a Custom Control to a dynamic datasource
The second part of this can be tricky. On your Custom Control you cannot use the "Simple Data Binding" option to bind your fields since you have no datasource set for the Custom Control, the datasource is dynamic.
The perfect solution for this is to use the Advanced -> Expression Language (EL) binding. For example, to bind the field to the "Comment" field, we would use "compositeData.docdatasource.Comment". Where....
- compositeData holds all the parameters for the Custom Control
- docdatasource is the parameter that we created that receives the datasource
- Comment is the field name on the Notes form
Now, with that said, there is an issue with this in 8.5. DDE tries to convert the EL expression to a Simple data binding when you save and reopen the Custom Control. So it works the first time you enter it, but loses the binding when you edit the Custom Control. However, it looks like this is fixed in 8.5.1.
Here's an example of the Custom Control used with multiple Data Sources in action:
You can download this example here