XPages-仅在日期字段中保存日期 [英] XPages - save date only in Date field

查看:50
本文介绍了XPages-仅在日期字段中保存日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用编辑框"控件来显示日期字段.保存XPage后,我只想保存日期(现在同时保存了日期和时间).有什么办法吗?

I'm using an Edit Box control to display a date field. When the XPage is saved, I would like to save the date only (now both date and time are being saved). Is there any way of doing this?

这是我的代码:

<xp:inputText id="dateReparatur" value="#{document1.dateReparatur}">
<xp:this.converter>
<xp:convertDateTime type="date" dateStyle="long">
</xp:convertDateTime>
</xp:this.converter>
<xp:dateTimeHelper></xp:dateTimeHelper>
</xp:inputText></xp:td>

更新:我现在已经实现了以下代码:

UPDATE: I have now implemented the following code:

var dt = currentDocument.getItemValueDateTime("dateReparatur");
var dateonly = dt.getDateOnly();
currentDocument.replaceItemValue("dateReparatur",dateonly);

这只是给我日期,但是在Notes中,字段类型现在是文本,而不是我希望的日期/时间.

This gives me the date only, however in Notes the field type is now text rather than Date/Time, which is what I was hoping for.

推荐答案

此代码对我有用:

    <xp:this.postSaveDocument><![CDATA[#{javascript:
        var dt:DateTime = document1.getItemValueDateTime("dateReparatur");
        dt.setAnyTime();
        currentDocument.getDocument(true).replaceItemValue("dateReparatur", dt); 
        currentDocument.getDocument(true).save()
    }]]></xp:this.postSaveDocument>

它仅在postSaveDocument事件上起作用.如果将相同的代码放入querySaveDocument事件中(当然没有文档save()行),则保存期间事件后的时间会污染日期字段.

It does work at postSaveDocument event only. If you put the same code into querySaveDocument event (without document save() line of course) the date field gets polluted with time after event during saving.

替代是在querySaveDocument事件上执行computeWithForm:

<xp:this.querySaveDocument><![CDATA[#{javascript:
    document1.getDocument(true).computeWithForm(true, true)
}]]></xp:this.querySaveDocument>

您必须在表单的日期字段中添加Input Translation公式:

You'd have to add an Input Translation formula to date field(s) in your form:

@Date(@ThisValue)

computeWithForm的性能较差,虽然有时会对字段值产生副作用,但可能是一个很好的解决方案,尤其是在您有很多此类仅日期字段的情况下.

computeWithForm has a poor performance and causes sometimes side effects on field values though but might be a good solution especially if you have a lot of such date-only-fields.

这篇关于XPages-仅在日期字段中保存日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆