David Navarre
David Navarre

Reputation: 1022

Concatenating parameters

I'm trying to concatenate a string in Expression Language to access a property of an object and failing to do so.

Within an XPage in Lotus Notes, I want to programatically select which field to which I want to bind the control on the current XPage.

The result I would like to achieve is as follows.

#{poDoc[advertisingDateStart];}

I have a variable named fieldName that would supply "advertisingDate" and simply want to append "Start" to this field and "End" to the end date field. I tried several variations that do not work, such as:

#{poDoc[fieldName{'Start'}];}

Note that it would work if I passed in "advertisingDateStart" and used

#{poDoc[fieldName];}

The goal is to be able to place a start date field and an end date field while dynamically binding based on configuration documents. That is, adding fields to my XPage using configuration documents and repeats instead of changing the design. Here is one of the ways I tried to create the ending date field:

<xp:inputText id="inputText5"
    style="padding-top:2px;text-align:left">
    <xp:this.rendered><![CDATA[#{javascript:rowData.getColumnValue("FieldType") == "Date Range"; }]]></xp:this.rendered>
    <xp:dateTimeHelper id="dateTimeHelper3"></xp:dateTimeHelper>
    <xp:this.converter>
        <xp:convertDateTime type="date"></xp:convertDateTime>
    </xp:this.converter>
    <xp:this.value><![CDATA[#{javascript:poDoc[fieldName+"End"];}]]></xp:this.value>
</xp:inputText>

I just can't figure it out.

Upvotes: 1

Views: 398

Answers (1)

W_K
W_K

Reputation: 868

Unfortunately, you cannot bind using 'javascript:' notation. In SSJS there is no way of pointing to an 'object property' (getter and setter) that you would like bound to component property.

Only Expression Language can do this with dot notation.

If you really need to bind to dynamic fields, you have to compute the fieldname before using it as Per Henrik Lausten suggested (xp:dataContext is the way to go). Since you want two date fields from one entry, you should use different variables for the new values, computing the value using Javascript

<xp:this.dataContexts> 
    <xp:dataContext var="fieldName"> 
       <xp:this.value>
        <![CDATA[#{javascript:rowData.getColumnValue ("FieldName");}]]>
       </xp:this.value>
     </xp:dataContext>
    <xp:dataContext var="fieldNameDateStart">
     <xp:this.value>
         <![CDATA[#{javascript:return rowData.getColumnValue ("FieldName") + "Start";}]]>
     </xp:this.value>
    </xp:dataContext> <xp:dataContext var="fieldNameDateEnd">
     <xp:this.value>
        <![CDATA[#{javascript:return rowData.getColumnValue ("FieldName") + "End";}]]>
     </xp:this.value>
    </xp:dataContext>
</xp:this.dataContexts> 

fieldName would be used for single field entries, while the others would be used only for start dates and end dates.

Upvotes: 2

Related Questions