XPage中的间隔计时器在刷新时丢失日期值

时间:2015-10-05 15:04:06

标签: xpages

您好我有一个'mail in'应用程序,并在'wallboard'上显示等待队列(行)的电子邮件。我希望每隔x秒刷新一次显示,使用包含邮件数据的重复的部分刷新。除了我有一个日期字段的问题,这可以正常工作,它可以正确显示,直到第一次刷新,当它转换为默认的1970年1月1日。我使用创建的日期来计算否。邮件等待的分钟数 - 这里没有显示。 任何帮助将不胜感激。

非常感谢

在XPage上我有:

<xp:scriptBlock
id="scriptBlockRefresh">
<xp:this.value>
        <![CDATA[
            setInterval(function() {
                XSP.partialRefreshGet("#{id:mailInPanel}", {})
            }, 5 * 1000)
        ]]>
</xp:this.value>
</xp:scriptBlock>

<xp:this.beforePageLoad><![CDATA[#{javascript:miniWallboardBean.loadOutstandingMailin();}]]></xp:this.beforePageLoad>

<xp:panel id="mailInPanel">
<xp:repeat id="repeat1" rows="30" value="#{miniWallboardBean.outstandingMailin}" var="rowData">
<xp:text escape="true" id="computedField1" value="#{rowData.from}"></xp:text>
<xp:text escape="true" id="computedField2" value="#{rowData.subject}"></xp:text>
<xp:text escape="true" id="computedField5" value="#{javascript:rowData.getCreatedDate().toJavaDate()}"></xp:text>           
</xp:repeat>
</xp:panel>

在我的Mailin课程中

import lotus.domino.DateTime;

public class Mailin {
private String from;
private String subject;
private DateTime createdDate;
private String owner;


public String getFrom()         {return from;}
public void setFrom(String from)        {this.from = from;}
public String getSubject()          {return subject;}
public void setSubject(String subject)  {this.subject = subject;}
public DateTime getCreatedDate()        {return createdDate;}
public void setCreatedDate(DateTime createdDate) {this.createdDate = createdDate;}
public String getOwner()            {return owner;}
public void setOwner(String owner)      {this.owner = owner;}
}

我从业务逻辑中的视图列中获取数据:

public List <Mailin> getOutstandingMailin(){    
    ArrayList<Mailin> outstandingMailin = new ArrayList<Mailin>();
    try {
        ViewEntryCollection entries = NCLWallboardUtil.getAllEntries("Server","DB","View"); //Method to get a collection

        if (entries !=null) {
            ViewEntry entry = entries.getFirstEntry();
            while (entry !=null){
            Mailin mailin = loadMailInFromEntry(entry);
            outstandingMailin.add(mailin);
            ViewEntry oldEntry = entry;
            entry = entries.getNextEntry(entry);
            oldEntry.recycle();
        }
            entries.recycle();
        }
            } catch (NotesException e) {
            e.printStackTrace(); 
        }
    return outstandingMailin;
}


private Mailin loadMailInFromEntry(ViewEntry entry) throws NotesException{
Mailin mailin = new Mailin();
mailin.setFrom((String) entry.getColumnValues().get(0));
mailin.setSubject((String) entry.getColumnValues().get(3));
mailin.setOwner((String) entry.getColumnValues().get(5));
mailin.setCreatedDate((DateTime) entry.getColumnValues().get(4));
return mailin;

}

在我的会话范围bean中,我有:

   public class MiniWallboardBean implements Serializable{

private static final long serialVersionUID = 1L;
private List <Mailin> outstandingMailin;
private MiniWallboard miniWB;   

public MiniWallboardBean(){
miniWB = new MiniWallboard();}

public void loadOutstandingMailin(){
    try{
    setOutstandingMailin(miniWB.getOutstandingMailin());
    }catch (Exception e){
        e.printStackTrace();
    }
    }


public void setOutstandingMailin(List <Mailin> outstandingMailil{
 this.outstandingMailin = outstandingMailin;}
public List <Mailin> getOutstandingMailin() {
  return outstandingMailin;}

1 个答案:

答案 0 :(得分:4)

与其他Domino对象一样,DateTimes不可序列化。因此,一旦最初的页面加载完成并且会话被回收,您的DateTime也将被回收。

将值存储为Java日期,您将没事。