Search code examples
xpages

XPages - Data binding issue


I am having issues computing a data binding field name. I don't receive any errors, however the radio button is in a "disabled" state. When I put simple data binding on that I know works, the radio loses it "disabled" state and works as expected, but obviously doesn't save to the field name I want. The end goal is to build a field name based on the combination of 2 custom properties. I've tried a variation of things, some of which are shown below:

1.    compositeData.dataSource[compositeData.fieldName #compositeData.radio1LabelText]

    2. compositeData.dataSource[compositeData.fieldName+compositeData.radio1LabelText]

    3. compositeData.dataSource[compositeData.fieldName,compositeData.radio1LabelText]

    4. try{
        var fieldName:string=compositeData.fieldName;
        var fieldLabel:string=compositeData.radio1LabelText;
        return compositeData.dataSource+"."+fieldName+fieldLabel;   
    }catch(e){
        openLogBean.addError(e,this.getParent());
    }

5. compositeData.dataSource[compositeData.fieldName += compositeData.radio1LabelText]

6.compositeData.dataSource[compositeData.fieldName.concat(compositeData.radio1LabelText)] 

Thanks

UPDATE in regards comments chat with Jesse:

    <xp:repeat id="repeat1" rows="30"
                        value="#{javascript:compositeData.labels}" var="rptLabels">
                        <tr>
<td>
<xp:panel>
<xp:this.dataContexts>
        <xp:dataContext var="concatRadioName1">
            <xp:this.value><![CDATA[#{javascript:var tmpString = "GIMS"+rptLabels+"Self";
var fieldName = tmpString.replace(/\s+/g, '');
print(fieldName);
return fieldName
}]]></xp:this.value>
        </xp:dataContext>
</xp:this.dataContexts>
                        <xp:radioGroup styleClass="no-margin">


                            <xp:this.value><![CDATA[#{compositeData.dataSource[concatRadioName1]}]]></xp:this.value>

                            <xp:selectItem itemValue="1" itemLabel=""></xp:selectItem>
                            <xp:selectItem itemValue="2" itemLabel=""></xp:selectItem>
                            <xp:selectItem itemValue="3" itemLabel=""></xp:selectItem>
                        </xp:radioGroup>
</xp:panel>

</td>

            </tr>
                    </xp:repeat>

Solution

  • For whatever reason, EL in XPages doesn't have a string concatenation operator, which makes this sort of thing tricky. Off the top of my head, I can think of two potential routes that could work:

    • Inside the custom control, you could have a dataContext that concatenates the two properties, like <xp:dataContext var="concatFieldName" value="#{compositeData.fieldName}#{compositeData.radio1LabelText}"/>. Then, you could use #{compositeData.dataSource[concatFieldName]} later on in the page.
    • If the values are either hard-coded on the calling page or can be computed using ${}-binding, you could use SSJS to generate a binding, similar to what you tried in #4 there. You could put the SSJS computation in a ${} binding, and then have the output be a string version of the #{} binding for the concatenated string. When you do a chain like that, the runtime will end up resolving the inner runtime binding properly.