0
votes

I have a repeat control that is gathering its data from a view. Displaying in a table is one column from the view. These entries can be variable. For each entry in the repeat control I would like to have a couple of user editable fields (comments and checkboxes). Since the amount and names of entries are dynamic I think dynamic field binding is the way to go. The problem is I have been struggling with it for a few days and have gotten no where.

So in the repeat I have a computedfield displying the value of the column. I was thinking of making the field name for the comments field the value of the computedfield. The datasource would be the same, just the fieldnames would change and be based on the entries in the row.

The previous entries stackoverflow entries about dynamic field binding all list passing custom properties, I still haven't gotten my head around those.

If the value of the computedfield1 = "One" then the datasource/field name for the inputText1 = "document1.One", and if the computedField1 = "Two" then the datasource inputText1 = "document1.Two"

Is this even possible?

1

1 Answers

2
votes

I'm a little confused by if you want these to be things you're setting to render at page load or if you want them to dynamically change based on user entered data, but I'll assume it's the former and give you an example.

If I'm iterating through a view in a repeat control, I probably have something like:

<xp:repeat rows="50" var="currRow" value="#{ViewName}" IndexVar="rowNum">
</xp:repeat>

Inside my repeat, I will put a reference to a custom class

<xp:repeat rows="50" var="currRow" value="#{ViewName}" IndexVar="rowNum">
    <xc:dynamicRowBinding dataSource="#{currentDocument}">
        <xc:this.binding1>
            <![CDATA[#{javascript: currRow.getColumnValue("binding1");}]]>
        </xc:this.binding1>
    </xc:dynamicRowBinding>
</xp:repeat>

What this is assuming is that the document you're binding things to on the XPage is declared as currentDocument, and that there is a column in your underlying view that is calculating the desired field binding for the current row based on the properties and values of that document.

In the custom control, the following exists:

defining dataSource

By defining dataSource and binding1 as properties within the custom control, they will be available as compositeData.

Thus, to bind a field using these components, we simply put the following definition in our custom control:

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

I hope this helps!