dmulv
dmulv

Reputation: 33

XPages: display DateTime value using browser's locale

I've some computed text on an XPage bound to a document data source, and trying display the date component of a Notes DateTime field using SSJS.

I've always used the doc.getItemValueDateTimeArray method, however it seems to be tied to the server's locale (if I change the browser's language from UK to US, the date format's still dd/mm/yyyy).

How do I output the date in a format that honours the browser's language setting?

Upvotes: 0

Views: 740

Answers (2)

Mark Leusink
Mark Leusink

Reputation: 3757

The getItemValueDateTimeArray() method returns a list (java.util.Vector to be exact) of NotesDateTime values. The XPages runtime will only honour the browser's language setting if you pass it a java.util.Date object.

There are a couple of methods you can use.

Bind the computed field directly to the document's field (recommended approach):

<xp:text
   escape="true"
   id="computedField1"
   value="#{document1.$revisions}">
</xp:text>

Use the toJavaDate() method of the NotesDateTime class to return a java.util.Date:

<xp:text
   escape="true"
   id="computedField1"
   value="#{javascript:var doc = document1.getDocument();
     var dt:NotesDateTime = doc.getItemValueDateTimeArray('$revisions').get(0);
     return dt.toJavaDate();}">
</xp:text>

Once you have a java.util.Date object you can also add a converter to the field to format the date, but the samples above will already listen to the browser's locale.

Upvotes: 1

Per Henrik Lausten
Per Henrik Lausten

Reputation: 21709

Try adding a converter (that displays the data source value directly without using doc.getItemValueDateTimeArray):

<xp:text escape="true" id="computedField1" value="#{document1.dateField}">
    <xp:this.converter>
        <xp:convertDateTime type="date"></xp:convertDateTime>
    </xp:this.converter>
</xp:text>

Upvotes: 0

Related Questions