Search code examples
xpagescompositecomputed-field

Xpages and computed field in a composite control


I've been able to successfully create dynamic field names and save the values for input fields using the technique described here: http://lpar.ath0.com/2014/04/07/repeated-xpages-input-controls-with-number-indexed-field-names/

I also have a computed field which has a number indexed name but whose value is computed based on a keyword choice. I can assign the dynamic field name for it like so:

<xp:text escape="true" id="computedField1">
    <xp:this.value><![CDATA[#{compositeData.dataSource[compositeData.fieldName2]}]]></xp:this.value>
</xp:text>

The property definition for this field looks like this:

enter image description here

and the call to the composite control looks like this:

<xc:cc_dynamicAssetItems 
row="#{(rownum lt 10)? '0':''}#{rownum}"
dataSource="#{document1}"
fieldName1="replace#{(rownum lt 10)? '0':''}#{rownum}"
fieldName2="budget#{(rownum lt 10)? '0':''}#{rownum}" >
</xc:cc_dynamicAssetItems>

I am at a loss however on how to pass the value to this computed field. The SSJS for it would have been:

var projectNumber = getComponent("ProjectNumber").getValue();
if(projectNumber == ""){
return "Nothing found";
}else{
return projectNumber + "A";
}

I'd appreciate some direction.

Thanks,

Dan


Solution

  • Instead of setting the value of your component, you should set the value of the underlying datasource. This means that your logic should not run in your computed field, than in your onChange event of the ProjectNumber component. Then you have to update e.g. document1.budget01 only, which is a lot faster.

    As an alternative, you can still pass a method binding* to your custom control, as described here: Pass javascript code to Custom Control

    (*: in your case a value binding)