4

I'm a problem understanding how to do dynamic binding to a edit control. The backend from has fields fItem01 fItem02... fPD01 fPD02.. fRQR01 fRQR02.. I can get the values for all the fields but having been able to defined the binding for edit control.

I've read all the posting on this subject but haven't figure out what I'm doing wrong. Also tried using a custom control with a property for the binding but that didn't work either.

Thanks for any help on this Bob

<xp:this.data>
    <xp:dominoView var="view1" viewName="vwMultItem"></xp:dominoView>
</xp:this.data>
<xp:table border="1">
    <xp:tr>
        <xp:td>
            <xp:label value="Title" id="label1"></xp:label>
        </xp:td>
        <!--<xp:td></xp:td>-->
    </xp:tr>
    <xp:repeat id="repeat1" rows="1" value="#{view1}" var="row">
        <xp:panel id="panelDocData">
            <xp:this.data>
                <xp:dominoDocument var="document1"
                    formName="frMultItem" action="editDocument"
                    documentId="#{javascript:row.getNoteID();}">
                </xp:dominoDocument>
            </xp:this.data>
            <xp:repeat id="repeat2" rows="3" var="rowItem" first="0"
                indexVar="indexVar">
                <xp:this.value><![CDATA[#{javascript:new Array("01", "02", "03")}]]></xp:this.value>    
                <xp:tr>
                    <xp:repeat id="repeat3" first="0" rows="2"
                        var="rowName">
                        <xp:this.value><![CDATA[#{javascript:new Array("fItem","fPD")}]]></xp:this.value>
                        <xp:td>
                            <xp:text escape="true" id="computedField1">
                                <xp:this.value><![CDATA[#{javascript:document1.getItemValueString(rowName+rowItem);
                                }]]></xp:this.value> </xp:text>                         
                        </xp:td>
                    </xp:repeat>
                        <xp:td>
                            <xp:inputText id="inputText1"
                                value="#{javascript:'#{document1.fRQR'+'01'+'}'}">
                            </xp:inputText></xp:td>
                </xp:tr>
            </xp:repeat>
        </xp:panel>
    </xp:repeat>
</xp:table>
Bob Yesenskiy
  • 414
  • 2
  • 15
  • The `value` attribute of editable components must be standard EL, not SSJS, to allow the component to be read/write. So `#{document1[fieldName]}` (where `fieldName` is a variable that stores the name of the field) is valid... any SSJS expression is not. – Tim Tripcony Aug 15 '13 at 17:47
  • Go here for more detailed information: http://www.timtripcony.com/blog.nsf/d6plinks/TTRY-86EMBS – Tim Tripcony Aug 15 '13 at 17:48
  • You can also reference this previous answer for another example: http://stackoverflow.com/questions/9719778/xpages-more-fields-unlimited-at-the-click-of-a-button/9720793#9720793 – Tim Tripcony Aug 15 '13 at 17:50

1 Answers1

1

As you know which fields you want to put into the repeat control you can calculate the fieldNames in inner repeat block completely with

javascript:["fItem"+rowItem,"fPD"+rowItem,"fRQR"+rowItem]

and then use them in edit control's value EL #{document1[fieldName]}.

<xp:repeat
    id="repeat2"
    var="rowItem"
    indexVar="indexVar">
    <xp:this.value><![CDATA[#{javascript:["01", "02", "03"]}]]></xp:this.value>
    <xp:tr>
        <xp:repeat
            id="repeat3"
            var="fieldName">
            <xp:this.value><![CDATA[#{javascript:["fItem"+rowItem,"fPD"+rowItem,"fRQR"+rowItem]}]]></xp:this.value>
            <xp:td>
                <xp:inputText
                    id="inputText2"
                    value="#{document1[fieldName]}">
                </xp:inputText>
            </xp:td>
        </xp:repeat>
    </xp:tr>
</xp:repeat>
Knut Herrmann
  • 30,880
  • 4
  • 31
  • 67
  • 2
    Please don't use `new Array()`. The Array constructor has side effects. `["fItem"+rowItem,"fPD"+rowItem,"fRQR"+rowItem]` produces the same result, but with less typing and less side effects. Same goes for `{ }` instead of `new Object()`. – Tim Tripcony Aug 15 '13 at 20:45
  • Tim could you elaborate on the side effects of new Array() and new Object() vs. [] and {}? – stwissel Aug 16 '13 at 07:23
  • 1
    @stwissel: [] is shorter, better to read, works well and is a bit safer **although** probablility is not very high that Array() is overwritten by included js files and there is no danger of having just one numeric parameter for new Array() in this case. – Knut Herrmann Aug 16 '13 at 13:21
  • Thank you Tim and Knut, I now know how to do dynamic bindings correctly. – Bob Yesenskiy Aug 16 '13 at 13:57