1

I have a notes form with a series of fields such as city_1, city_2, city_3 etc.

I have an XPage and on that XPage I have a repeat.

The repeat 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) ;

Within the repeat I have a custom control which is used to surface the fields city_1 through city_10

The repeat has a custom property docdatasource which is passed in It also has a string custom property called cityFieldName which is computed using the repeat collection name so that in the first repeat row it is city_1 and in the second it is city_2 etc..

The editable text field on the custom control is bound using the EL formula compositeData.docdatasource[compositeData.cityFieldName]

This works fine but each time I add new fields I have to remember to create a new custom property and then a reference to it on the parent page.

I would like to be able to simply compute the data binding such as

compositeData.docdatasource['city_' + indexvar]

where indexvar is a variable representing the current row number.

Is this possible ? I have read that you cannot use '+' in Expression Language.

Sean Cull
  • 503
  • 3
  • 17

3 Answers3

2

First: you wouldn't need an array for a counter. Just 10 would do (the number) - repeats 10 times too. But you could 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 bind city,

#{datasource.indexvar[1]}

to bind street. etc.

Carries a little the danger of messing with the sequence of the array, if that's a concern you would need to dig deeper in using an Object here.

stwissel
  • 20,110
  • 6
  • 54
  • 101
  • That looks pretty ingenious. It doesn't quite give me what I was after because both the XPage and the Custom Control need to be updated every time a new field is added to the Custom Control but it is a lot less hassle than creating new custom property definitions each time - note I have not tried the code yet. – Sean Cull Jan 29 '12 at 00:03
1

compute to javascript and use something like

var viewnam = "#{" +  (compositeData.searchVar )+ "}"
return viewnam

make sure this is computed on page load in the custom control

Mark hughes
  • 153
  • 8
  • Hi Mark, I have tried this and couldn't get it working. There is a demo database at [link](http://focul.bucket1.s3.amazonaws.com/public_downloads/sean/SO_8992506_2.nsf) if you fancy a go. – Sean Cull Jan 29 '12 at 00:01
0

I was never able to do the addition within EL but I have been very successful with simply computing the field names outside the custom control and then passing those values into the custom control.

I can send you some working code if you wish from a presentation I gave.

Russell Maher
  • 378
  • 1
  • 7
  • see response to answer 1, I think what you are suggesting is the same ? thanks for the offer of code though – Sean Cull Jan 24 '12 at 19:40
  • So you do not want to have one property for city and a separate property for county? – Russell Maher Jan 24 '12 at 19:46
  • no, I really only want to have a property for the datasource so that as I add new fields I have much less work to do. - see response to answer 1 above - Mark Hughes answer looks promising if it works. – Sean Cull Jan 24 '12 at 19:54
  • Did this work? I tried to get it to work but coudln't. Again. I'd really like to see a working example of this. – Russell Maher Jan 25 '12 at 15:45
  • Russell I couldn't get it to work either. Am following up with Mark and Stephan. – Sean Cull Jan 29 '12 at 00:09