1
votes

I have a xp:dataTable where one column has computed Field that shows DateTime value. I want to show only time for current date (Today) and date/Time for all other dates. Here is what I put into computed field converter:

<xp:text escape="true" id="computedField1">
<xp:this.value><![CDATA[#{javascript:rowData.getColumnValue("START_DATE")}]]></xp:this.value>
<xp:this.converter>
    <xp:convertDateTime type="date">
        <xp:this.type>
            <![CDATA[${javascript:
                var inputDate = new Date(this.value);
                var todaysDate = new Date();
                if(inputDate.setHours(0,0,0,0) == todaysDate.setHours(0,0,0,0)){
                    return "time";
                } else {
                    return "both";
                }
            }]]>
        </xp:this.type>
    </xp:convertDateTime>
</xp:this.converter>

but it doesn't work. Any ideas? Should I format it somehow with CSS? Thanks

1

1 Answers

0
votes

You can't calculate converterDateTime's type for every value individually. The code can't be executed at run time. It runs only once as code starts with ${... - #{.. is not allowed.

Use

  • a custom converter to create the date/time string or
  • two computed fields (a date/time and a time only field) and use rendered code to decide which one to show.