Bind an edit field inside a custom control to a form field programmatically
I have a notes form with a number of fields like city_1, city_2, city_3, etc.
I have an XPage and on this XPage I have a repeat.
Repetition is based on an array with ten values 1 - 10
var repArray = new Array() ;
for (var i=1;i<=10;i++) {
repArray.push(i) ;
}
return (repArray);
Inside the replay, I have a custom control that is used to handle city_1 fields through city_10
The repeat has a custom docdatasource property that is passed to It also has a custom string property called cityFieldName that is calculated using the repeat name of the collection, so the first line of the repeat is city_1, the second is city_2, and so on.
Editable text box in custom control is linked using EL formula compositeData.docdatasource [compositeData.cityFieldName]
This works great, but every time I add new fields I have to remember to create a new custom property and then link to it on the parent page.
I would like to just calculate the data binding like
compositeData.docdatasource['city_' + indexvar]
where indexvar is a variable representing the current line number.
Is it possible? I read that you cannot use "+" in expression language.
source to share
First: you don't need an array for the counter. Total 10 will do (number) - repeat 10 times. But you can build an array of arrays:
var repArray = [];
for (var i=1;i<=10;i++) {
repArray.push(["city","street","zip","country","planet"]) ;
}
return repArray;
then you should be able to use
#{datasource.indexvar[0]}
to tie the city
#{datasource.indexvar[1]}
to tie the street. and etc.
A little shy of the danger of messing around with the sequence of an array, if that's a concern you should delve deeper into the use of an object here.
source to share