I changed the allItems as follows:
public ArrayList<PaymentItem> allItems(){
ArrayList<PaymentItem> rtn = new ArrayList<PaymentItem>();
try{
for (Integer n = 1; n <= internalMap.size(); n++) {
String thisKey = n.toString();
PaymentItem pItem = new PaymentItem();
pItem = this.internalMap.get((thisKey ).toString());
if (debug) System.out.println("Copy item key = " + pItem.getExpPayDate().toString() );
rtn.add((n - 1),pItem);
}
for (Integer n = 0; n< rtn.size(); n++){
if (debug) System.out.println("dates from ArrayList = " + rtn.get(n).getExpPayDate().toString());
}
if (debug) System.out.println("Return allItems " + rtn.toString());
return rtn;
}catch(Exception e){
rtn = null;
System.out.println("Error in PaymentMap allItems " + e.toString());
return rtn;
}
}
and when it runs it prints the following:
10/09/2015 12:24:37 PM HTTP JVM: Copy item key = Thu Sep 24 12:00:00 MDT 2015
10/09/2015 12:24:37 PM HTTP JVM: Copy item key = Sat Sep 05 12:00:00 MDT 2015
10/09/2015 12:24:37 PM HTTP JVM: Copy item key = Fri Aug 28 12:00:00 MDT 2015
10/09/2015 12:24:37 PM HTTP JVM: dates from ArrayList = Thu Sep 24 12:00:00 MDT 2015
10/09/2015 12:24:37 PM HTTP JVM: dates from ArrayList = Sat Sep 05 12:00:00 MDT 2015
10/09/2015 12:24:37 PM HTTP JVM: dates from ArrayList = Fri Aug 28 12:00:00 MDT 2015
10/09/2015 12:24:37 PM HTTP JVM: Return allItems [ca.wfsystems.core.PaymentItem@19741974, ca.wfsystems.core.PaymentItem@1cc81cc8, ca.wfsystems.core.PaymentItem@1f491f49]
so the ArrayList is populated with the correct dates and the issue seems to be with the repeat which repeats over the three PaymentItem(s) so it knows there are three item to repeat over, the ArrayList in payObj.allItems() is calculated correctly because in the printout in the allItems method it clearly has the correct three PaymentItems. The definition of the Value of the repeat would seem to work OK and pItem is of type PaymentItem, but ......
If I get the value using payObj,get(key).expPayDate I get the correct date, but if I use pItem.expPayDate I do not. I'm wondering if there is an issue with the PaymentItem get(key) in the paymentMap class that is causing a problem.
<xp:repeat id="repeat1" rows="30" var="pItem"
indexVar="rIndex" value="#{javascript:payObj.allItems()}">
<xp:text escape="true" id="computedField5"
value="#{javascript:pItem.expPayDate}">
<xp:this.converter>
<xp:convertDateTime type="date"></xp:convertDateTime>
</xp:this.converter>
</xp:text>
<xp:br></xp:br>
</xp:repeat>
Below is the PaymentMap Class which imports the PaymentItem Class. I have removed some of the methods from the PaymentMap that are not at issue here. The PaymentMap class is defined as a managed Bean called payObj. The process is that in the BeforePageLoad I call payObj.buildMap() which goes out to disk and reads N Notes Payment documents and stores the results in a HashMap<string,paymentMap>. I have a method payObj.saveItems() which is called in the QuerySave event of the mainDocument. There are methods to create a new paymentItem and other things which are not in play with the current issue and are functioning in any case.
So the paymentMap Class Looks like this:
package ca.wfsystems.core;
import javax.faces.context.FacesContext;
import java.io.Serializable;
import java.util.Collection;
import java.util.HashMap;
import java.util.TreeMap;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.Date;
import java.math.BigDecimal;
import lotus.domino.Database;
import lotus.domino.View;
import lotus.domino.ViewEntry;
import lotus.domino.ViewEntryCollection;
import lotus.domino.DateTime;
import lotus.domino.Document;
import com.ibm.xsp.extlib.util.ExtLibUtil;
import ca.wfsystems.core.PaymentItem;
import ca.wfsystems.core.ApplicationMap;
import ca.wfsystems.core.AppProperties;
import ca.wfsystems.core.Utils;
public class PaymentMap implements Serializable, Map<String, PaymentItem> {
private static final long serialVersionUID = 1L;
private Boolean debug = true;
private Map<String, PaymentItem> internalMap = new HashMap<String, PaymentItem>();
public PaymentMap() {
}
public String newItem(String lKey, Date expPayDate) {
try {
if (debug)
System.out.println("In New Item");
Integer n = (internalMap.size() + 1);
String key = n.toString();
PaymentItem pItem = new PaymentItem();
pItem.setChanged(true);
pItem.setUnid(lKey);
pItem.setPaymentID("");
pItem.setExpPayDate(expPayDate);
BigDecimal bd = new BigDecimal("0");
pItem.setPayAmount(bd);
internalMap.put(key, pItem);
this.reBuildMap();
return key;
} catch (Exception e) {
System.out.println("Error in newItem " + e.toString());
return null;
}
}
public ArrayList<PaymentItem> allItems(){
ArrayList<PaymentItem> rtn = new ArrayList<PaymentItem>();
try{
for (Integer n = 1; n <= internalMap.size(); n++) {
String thisKey = n.toString();
PaymentItem pItem = new PaymentItem();
pItem = this.internalMap.get((thisKey ).toString());
if (debug) System.out.println("Copy item key = " + pItem.getExpPayDate().toString() );
rtn.add((n - 1),pItem);
}
for (Integer n = 0; n< rtn.size(); n++){
if (debug) System.out.println("dates from ArrayList = " + rtn.get(n).getExpPayDate().toString());
}
if (debug) System.out.println("Return allItems " + rtn.toString());
return rtn;
}catch(Exception e){
rtn = null;
System.out.println("Error in PaymentMap allItems " + e.toString());
return rtn;
}
}
public void buildMap(String lKey) {
try {
if (debug)
System.out.println("In buildMap of PaymentMap");
if (debug)
System.out.println("Map Updated");
Map sessionscope = (Map) ExtLibUtil.resolveVariable(FacesContext
.getCurrentInstance(), "sessionScope");
String app = sessionscope.get("ssApplication").toString();
if (debug)
System.out.println("Building Payment Map " + app);
ApplicationMap appProps = (ApplicationMap) ExtLibUtil
.resolveVariable(FacesContext.getCurrentInstance(),
"appProps");
AppProperties thisApp = appProps.get(app);
Database appDB = thisApp.getAppDB();
if (debug)
System.out.println("Got DB " + appDB.getTitle());
View vwPayment = appDB.getView("vwPaymentsByLinkKey");
ViewEntryCollection veCol = vwPayment.getAllEntriesByKey(lKey);
if (debug)
System.out.println("Got Collection " + veCol.getCount());
if (veCol.getCount() == 0) {
// No matching Documents
if (debug)
System.out.println("No Matches Found ");
return;
} else {
for (int n = 1; n <= veCol.getCount(); n++) {
if (debug)
System.out.println("in loop n = " + n);
ViewEntry ve = veCol.getNthEntry(n);
Document pDoc = ve.getDocument();
PaymentItem pItem = new PaymentItem();
pItem.setUnid(pDoc.getUniversalID());
pItem.setChanged(false);
// String key = s.evaluate("@Unique").get(0).toString();
// ExpPayDate
try {
DateTime dt = (DateTime) pDoc
.getItemValueDateTimeArray("ExpPayDate").get(0);
Date pDate = dt.toJavaDate();
pItem.setExpPayDate(pDate);
} catch (Exception e) {
// date error
}
// ActualPayDate
try {
if (debug)
System.out.println("Get ActualPayDate ");
DateTime dt = (DateTime) pDoc
.getItemValueDateTimeArray("actualPayDate")
.get(0);
Date pDate = dt.toJavaDate();
if (debug)
System.out.println("ActualPayDate = "
+ pDate.toString());
pItem.setActualPayDate(pDate);
if (debug)
System.out.println("Set ActualPayDate ");
} catch (Exception e) {
// date error
if (debug)
System.out.println("ActualPayDate = null");
}
// Payment Amount
try {
String amt = pDoc.getItemValue("Amount").get(0)
.toString();
if (debug)
System.out.println("Get Amount " + amt);
BigDecimal bd = new BigDecimal(amt);
pItem.setPayAmount(bd);
if (debug)
System.out.println("Set Amount " + bd.toString());
} catch (Exception e) {
// amount = null
BigDecimal bd = new BigDecimal("0");
pItem.setPayAmount(bd);
if (debug)
System.out.println("Set Amount " + bd.toString());
}
pItem.setPaymentID(pDoc.getItemValueString("PaymentID"));
if (debug)
System.out.println("Update Internal Map");
String key = Integer.toString(n);
internalMap.put(key, pItem);
Utils.recycleObjects(pDoc, pItem, ve);
}// for loop
} // else main process
Utils.recycleObjects(appDB, vwPayment, veCol);
} catch (Exception e) {
System.out.println(e.toString());
}
}
public boolean containsKey(Object key) {
return this.internalMap.containsKey(key);
}
public boolean containsValue(Object value) {
return this.internalMap.containsValue(value);
}
public Set<java.util.Map.Entry<String, PaymentItem>> entrySet() {
return this.internalMap.entrySet();
}
public PaymentItem get(Object key) {
try {
if (this.internalMap.containsKey(key)) {
if (debug)
System.out.println("Got internalMap");
return this.internalMap.get(key);
} else {
if (debug)
System.out.println("No Key in PaymentMap " + key);
PaymentItem pItem = new PaymentItem();
return pItem;
}
} catch (Exception e) {
System.out.println("PaymentMap" + e.toString());
PaymentItem pItem = new PaymentItem();
return pItem;
}
}
public boolean isEmpty() {
return this.internalMap.isEmpty();
}
public Set<String> keySet() {
return this.internalMap.keySet();
}
public PaymentItem put(String key, PaymentItem value) {
return this.internalMap.put(key, value);
}
public void putAll(Map<? extends String, ? extends PaymentItem> m) {
this.internalMap.putAll(m);
}
public PaymentItem remove(Object key) {
return this.internalMap.remove(key);
}
public int size() {
return this.internalMap.size();
}
public Collection<PaymentItem> values() {
return this.internalMap.values();
}
public void clear() {
// TODO Auto-generated method stub
}
}
The PaymentItem Class is as follows:
package ca.wfsystems.core;
import java.io.Serializable;
import java.util.Date;
import java.math.BigDecimal;
public class PaymentItem implements Serializable {
private static final long serialVersionUID = 1L;
private Boolean debug = true;
public PaymentItem() {};
private Date expPayDate;
private Date actualPayDate;
private Number payAmount;
private String paymentID;
private Boolean changed;
private String unid;
public Date getExpPayDate() {
return expPayDate;
}
public void setExpPayDate(Date expPayDate) {
this.expPayDate = expPayDate;
}
public Date getActualPayDate() {
return actualPayDate;
}
public void setActualPayDate(Date actualPayDate) {
this.actualPayDate = actualPayDate;
}
public Number getPayAmount() {
return payAmount;
}
public void setPayAmount(BigDecimal payAmount) {
this.payAmount = payAmount;
}
public String getPaymentID() {
return paymentID;
}
public void setPaymentID(String paymentID) {
this.paymentID = paymentID;
}
public Boolean getChanged() {
return changed;
}
public void setChanged(Boolean changed) {
this.changed = changed;
}
public void setUnid(String unid) {
this.unid = unid;
}
public String getUnid() {
System.out.println("Get UNID = " + unid);
return unid;
}
}