Reputation: 1343
I have several fields on my Notes Document
FieldA_1 FieldA_2 FieldA_3 FieldA_4
FieldB_1 FieldB_2 FieldB_3 FieldB_4
On a composite control I have 2 edit boxes FieldA FieldB
I have a compositeData.ATM_NUM defined a custom control that is a drop down list with the values 1,2,3,4.
How do I bind the edit boxes on my control to their corresponding document fields using the composite data available?
For example, I wanted to do something like: "FieldA_"+ compositeData.ATM_NUM.
I tried the javascript solution in this thread:
Binding an edit box within a custom control to a form field programatically
But it did not seem to work.
Upvotes: 2
Views: 4510
Reputation: 20384
An example for data binding for a custom control is this:
Create a custom control, add 2 custom properties: BindTo (String), canEdit (Boolean). Quite often you have the need to have a field readonly based on the state of your business logic rather than the fact that the rest is in edit mode.
<xp:listBox id="listBox1"
rendered="#{compositeData.canEdit}">
<xp:this.value><![CDATA[${javascript:"#{"+compositeData.BindTo+"}"}]]></xp:this.value>
<xp:selectItem itemLabel="red"></xp:selectItem>
<xp:selectItem itemLabel="blue"></xp:selectItem>
<xp:selectItem itemLabel="green"></xp:selectItem>
</xp:listBox>
<xp:text id="textForListbox"
rendered="#{!compositeData.canEdit}">
<xp:this.value><![CDATA[${javascript:"#{"+compositeData.BindTo+"}"}]]></xp:this.value>
</xp:text>
The advantage of this approach (using ${javascript:"#{"+compositeData.BindTo+"}"}
) is that you can bind that control to anything: a document, a scope variable, a bean etc.
Upvotes: 6
Reputation: 3355
The problem is related to the time that compositeData is ready for your use. At the start it evaluates to "0" when your custom control is ready.
Try this:
<xp:inputText id="inputText1"
value="${javascript:'#{document1.SomeField'+compositeData.SomeParam+'}'}">
</xp:inputText>
It's important to use "$" sign there. It will create a binding to SomeField1, SomeField2 and so forth depending on SomeParam.
Upvotes: 5
Reputation: 21709
Try the following as value for e.g. field A:
<xp:inputText value="#{document['FieldA'+compositeData.ATM_NUM]}" />
You could also extend the property of the custom control to include the whole field name (and thereby transfer e.g. "FieldA_1" to the custom control). Then you should be able to do the following:
<xp:inputText value="#{document[compositeData.fieldName]}" />
Upvotes: 11