Reid Rivenburgh
Reid Rivenburgh

Reputation: 403

Update XPages text value from within a repeat?

I feel like I'm just not understanding something about the XPages lifecycle here. I have an xp:text control, with a value of viewScope.count. Initially, that's null. After the xp:text, I have a repeat that's performing a calculation and returning an array of objects for its value. At the end of the repeat's value section, I'm trying to update the xp:text with a count of the things in the array:

viewScope.count = myArray.length;

The xp:text isn't being updated with that value, though. Should this work? Do I need to do a manual refresh of the xp:text when I modify viewScope.count? TIA!

Upvotes: 2

Views: 182

Answers (2)

stwissel
stwissel

Reputation: 20384

Take a step back and rethink the approach. Inside the code you use for your repeat you update something outside.

Not looking at 'does it work' I would claim 'bad idea'. Such side effects make maintenance a nightmare (and are not very MVC).

The better approach (IMHO):

Create an object data source. AFAIK that can be a JSON object if you are not comfortable with Java. That object would have all the needed properties for your repeat and your counter display. It serves as your model.

Then bind the repeat and the text field to the model and you are good.

Makes sense?

Upvotes: 1

Patrick Sawyer
Patrick Sawyer

Reputation: 1382

You should be able to use the index of the repeat to give you a count.

enter image description here

Upvotes: 1

Related Questions