I finally figured this out, so I figured I would post it in case anyone else is having the same issue with custom controls that I have been having. In all my searches, I didn’t find the answer so I had to figure it out myself.
I wanted to create a custom control that contained a field that was bound to a document data source on the parent XPage. Because I wanted to be able to do multiple copies of this, the field name could not be hard-coded into the field on the control. I wanted to do this so I could create controls that do standard validations, like a masked phone number field, or a field that must match the value of another field to verify duplicate entry. I can already do this as one-of fields on an XPage, but I wanted to make a custom control to do this.
The problem was the data binding. Try as I might, I couldn’t figure out how to create a custom control whose fields are bound to a data source on the parent XPage. I found this document (http://www-10.lotus.com/ldd/ddwiki.nsf/dx/09082009095808AMWEBJDV.htm) but it didn’t appear to work. After much fiddling and banging of my head on the desk, I finally got it to work. Here is what I did:
I created a custom control with two properties: source and sourceField. source I set to a type of com.ibm.xsp.model.DataSource, like the above article suggested, but I changed the editor to a “Method Binding Editor”. I don’t know if this is necessary, but if it works, I’m happy. sourceField is just a string that contains the name of the field you want to bind to.
Then I created a field on the custom control and used the advanced data binding to use an Expression Language expression to bind the field:
compositeData.source[compositeData.sourceField]
That’s it for the custom control (add validators, extra markup, etc. at your discretion)
Add the custom control to an XPage and set the sourceField property to a field name (doesn’t have to be on the form) For the source property, because of the editor selected for that control, you can only compute the value. Simply put in the name of the data source. e.g. if your data source is document1, then just type in document1. Done. Add a save button to the page to test.
Now to put some ice on my forehead…