1
votes

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

2
Don't ask the component, ask the datasource. Which is in your case document1.Sven Hasselbach
Sven, how can I assign a dynamic value to the computed field name and also give it a computed value? It's not clear from your answer how I can do that. Do you have an example? I'm more of a visual learner :)Dan Soares

2 Answers

1
votes

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)

-1
votes

did you try javascript instead expression language

ex: fieldName1="#{javascript: 'replace'+(rownum > 10? '0':'')+rownum}"