Desmond Sim
Desmond Sim

Reputation: 211

xpages retrieve value from Date list

Question:

  1. I store my Date value in list using code below.

    if (document1.hasItem("NotifyDate")){
        var nd = document1.getItemValue("NotifyDate");
        nd.addElement(session.createDateTime(@Now()));
        document1.setValue("NotifyDate", nd);
    }else{
        document1.setValue("NotifyDate", session.createDateTime(@Now()));
    }
    
  2. I want to retrieve it to display in webpage everytime i append an item.

    I18n.toString(document1.getItemValue("NotifyDate").lastElement().toJavaDate(), "dd/MM/yyyy") +")"
    

Problem :

  1. List item i only can get last element. How can i get all element of one field to display it

enter image description here

enter image description here

enter image description here

Upvotes: 0

Views: 93

Answers (2)

Hubert
Hubert

Reputation: 146

Just use loop to create output string.

var result="Status notification ( ";
for(var i=0; i<document1.getItemValue("NotifyDate").length;i++){
    result+= I18n.toString(document1.getItemValue("NotifyDate").get(i).toJavaDate(), "dd/MM/yyyy") +" "
}
result+=")"
return result

Upvotes: 1

Per Henrik Lausten
Per Henrik Lausten

Reputation: 21709

You can use a repeat to list each value from the date field. Here's an example:

<xp:repeat value="#{document1.NotifyDate}" var="singleDate" removeRepeat="true">
    I18n.toString(singleDate.toJavaDate(), "dd/MM/yyyy")
</xp:repeat>

Upvotes: 0

Related Questions