Dynamic data binding?

I have multiple fields in a 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 fields FieldA FieldB

I have a compositeData.ATM_NUM that defines a custom control that is a dropdown with values ​​1,2,3,4.

How do I bind my control's edit fields to the corresponding document fields using the available composite data?

For example, I wanted to do something like: "FieldA _" + compositeData.ATM_NUM.

I tried the javascript solution in this thread:

Programmatically bind an edit field inside a custom control to a form form

But it didn't work.

+2


source to share


3 answers


Try the following as a value for example. field A:

<xp:inputText value="#{document['FieldA'+compositeData.ATM_NUM]}" />

      



You can also extend the custom control property to include the fully qualified field name (and thus pass, for example, "FieldA_1" to the custom control). Then you should be able to do the following:

<xp:inputText value="#{document[compositeData.fieldName]}" />

      

+11


source


The problem has to do with the time when the composite date is ready for use. Initially, it evaluates to "0" when the user control is ready.

Try the following:



<xp:inputText id="inputText1" 
           value="${javascript:'#{document1.SomeField'+compositeData.SomeParam+'}'}">
</xp:inputText>

      

It is important to use the "$" sign. It will create a binding to SomeField1, SomeField2, etc. Depending on SomeParam.

+5


source


An example of data binding for a custom control:

Create a custom control, add 2 custom properties: BindTo (String), canEdit (Boolean). Quite often, you need to have a read-only field based on the state of your business logic rather than the fact that others are 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 this control to everything: document, scope variable, bean, etc.

+5


source







All Articles