How can I access the value of an computed field in a repeat control? In the example below, I have cfT5Budget in a repeat control. I want to be able to access the value of each of the cfT5Budget control (repeat1:0:cfT5Budget, repeat1:1:cfT5Budget, etc..)
I want to be able to have that same value replicated into my second repeat control. I will be doing other stuff in the second control but for this example, it's just a simple code.
<xp:table>
<xp:repeat id="repeat1" var="rowItem1" indexVar="indexVar1">
<xp:this.value><![CDATA[#{javascript:['a', 'b', 'c']}]]></xp:this.value>
<xp:tr>
<xp:td>
<xp:text escape="true" id="cfT5Budget" value="#{javascript:5 + indexVar1}">
</xp:text>
</xp:td>
</xp:tr>
</xp:repeat>
</xp:table>
<xp:table>
<xp:repeat id="repeat2" var="rowItem2" indexVar="indexVar2">
<xp:this.value><![CDATA[#{javascript:getComponent('repeat1').getValue()}]]></xp:this.value>
<xp:tr>
<xp:td>
<xp:text escape="true" id="cfT5Budget2" value="#{javascript:VALUE OF cfT5Budget GOES HERE}">
</xp:text>
</xp:td>
</xp:tr>
</xp:repeat>
</xp:table>
Thank you in advance :)
The short answer: use data binding.
The long answer:
In MVC your code should not interact with the View (a.k.a the fields), but rather the model (a.k.a the data). So instead of computing the values like in your example, you bind them using the variable name provided in the repeat.
You interact with that collection (Array) not the fields. This makes code easier and more robust since the code doesn’t need to care what UI element is used.
Hope that helps