Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Date 在用户返回到视图之前,按日期范围过滤的XPages视图可以完美地工作_Date_Filter_Xpages - Fatal编程技术网

Date 在用户返回到视图之前,按日期范围过滤的XPages视图可以完美地工作

Date 在用户返回到视图之前,按日期范围过滤的XPages视图可以完美地工作,date,filter,xpages,Date,Filter,Xpages,我有一个带有两个日期字段的XPage和一个绑定到视图的repeat控件。在每个日期字段中选择日期后,我的代码将创建一个日期范围,并使用视图的“keys”参数仅返回视图中两个日期之间的文档。这很好用。当一个人离开视图然后返回时,问题就出现了。我有一个pagerSaveState控件,它可以将视图恢复到导航回视图时的状态,但会出现错误:com.ibm.xsp.facesceptionex:Vector中未知或不受支持的对象类型 视图的XML如下所示: <xp:this.data>

我有一个带有两个日期字段的XPage和一个绑定到视图的repeat控件。在每个日期字段中选择日期后,我的代码将创建一个日期范围,并使用视图的“keys”参数仅返回视图中两个日期之间的文档。这很好用。当一个人离开视图然后返回时,问题就出现了。我有一个pagerSaveState控件,它可以将视图恢复到导航回视图时的状态,但会出现错误:
com.ibm.xsp.facesceptionex:Vector中未知或不受支持的对象类型

视图的XML如下所示:

<xp:this.data>
    <xp:dominoView var="view1" viewName="ByDeliveryDate"
        keysExactMatch="true"
        keys="#{javascript:sessionScope.selectedDateRange}">

    </xp:dominoView>
</xp:this.data>
function doDateRangeSearch() {

var vValStart = @Date(getComponent('StartDate').getValue());
if(vValStart==null||vValStart=='')vValStart = @Date(@Year(@Today()),1,1,0,0,0);

var vValEnd = @Date(getComponent('EndDate').getValue());
if(vValEnd==null||vValEnd=='')vValEnd = @Today();

var vDateRange = session.createDateRange(vValStart, vValEnd);
var vDateVector:java.util.Vector = new java.util.Vector();
vDateVector.addElement(vDateRange);
if(vDateVector.isEmpty())vDateVector = null;

sessionScope.selectedStartDate = vValStart;
sessionScope.selectedEndDate = vValEnd;
sessionScope.selectedDateRange = vDateVector;

/* reset the pager to the first page because if there is only one search 
 * result to display and if the pager was on anything except the first 
 * page the search result is not displayed
 */
var pager:com.ibm.xsp.component.xp.XspPager = getComponent("pager1"); 
pager.gotoPage(0);
}
有人能告诉我为什么返回视图会导致此错误吗

更新:

<xe:djDateTextBox
    id="StartDate"
    defaultValue="#{javascript:sessionScope.selectedStartDate}"
    value="#{sessionScope.selectedStartDate}">
    <xp:this.converter>
        <xp:convertDateTime type="date"
            dateStyle="full">
        </xp:convertDateTime>
    </xp:this.converter>
</xe:djDateTextBox>
<xe:djDateTextBox
    id="EndDate"
    defaultValue="#{javascript:sessionScope.selectedEndDate}"
    value="#{sessionScope.selectedEndDate}">
    <xp:this.converter>
        <xp:convertDateTime type="date"
            dateStyle="full">
        </xp:convertDateTime>
    </xp:this.converter>
</xe:djDateTextBox>
根据Panu的建议,我向视图的queryOpen事件添加了以下代码:

print("queryOpen: opening date range view");
if(sessionScope.selectedDateRange == null){
    print("selectedDateRange is null")
}else{
    for (var s in sessionScope.selectedDateRange) print(s);
}
print("queryOpen: completed");
<xp:button value="Go" id="FirstColumnSearchButton"
    styleClass="lotusBtn goButton">
    <xp:eventHandler event="onclick"
        submit="false" refreshMode="partial" refreshId="viewHolder">
    </xp:eventHandler>
</xp:button>
在我的web浏览器中,我导航到该视图。该视图在第一页显示最新文档,因为这是我在此会话中第一次访问该视图。这是控制台上显示的内容: 2013年10月18日10:45:23 HTTP JVM:queryOpen:开始日期范围视图
2013年10月18日10:45:23 HTTP JVM:SelectedDaterRange为空
2013年10月18日10:45:23 HTTP JVM:queryOpen:已完成

接下来,我在两个日期字段中选择了一些日期,并单击了调用我的SSJS函数的按钮。已正确执行搜索,仅显示日期范围内的文档。这是控制台上显示的内容:
2013年10月18日10:45:48 HTTP JVM:queryOpen:开始日期范围视图
2013年10月18日10:45:48 HTTP JVM:01/08/2013 00:00:00 GDT-2013年10月18日00:00:00 GDT
2013年10月18日10:45:48 HTTP JVM:queryOpen:已完成

我点击其中一个文档打开它,然后返回视图。我看到的是错误页面。这是控制台上显示的内容:
2013年10月18日10:46:16 HTTP JVM:queryOpen:开始日期范围视图
2013年10月18日10:46:16 HTTP JVM:null
2013年10月18日10:46:16 HTTP JVM:queryOpen:completed
2013年10月18日10:46:16 HTTP JVM:com.ibm.xsp.webapp.FacesServlet$ExtendedServletException:com.ibm.xsp.FacesExceptionEx:向量中的对象类型未知或不受支持


基于上述情况,sessionScope.SelectedDaterRange似乎仍然存在,但已丢失其所有内容。

若要调试,请将此代码作为
键的第一行
参数:

print(sessionScope.selectedDateRange);
您也可以尝试以下方法:

for (var s in sessionScope.selectedDateRange) print(s);
for (var s in sessionScope.selectedDateRange) print(typeof s);
这样,当您得到错误时,您将看到向量中的内容

可能日期范围已从sessionScope中消失,您需要再次将其放置在那里。如果需要,可以将其放置在
参数中

更新


当您发现您的日期范围将从sessionScope中消失。这是因为
DateRange
lotus.domino
对象。它们是不可序列化的,并且不会停留在作用域变量中。作为一种解决方法,您可以将日期存储到sessionScope中,作为
java.util.Date
(或
Calendar
)并根据每次访问页面时的日期范围创建
DateRange

我找到了如何让它工作的方法。感谢朱利安和帕努的建议。下面是我如何解决这个问题的。我把它贴在这里,以防有人想做类似的事情

首先,创建一个视图,其中第一个排序列包含日期。将其设置为日期/时间列

其次,在显示视图的自定义控件上,添加两个日期字段,如下所示:

开始日期字段:

<xe:djDateTextBox
    id="StartDate"
    defaultValue="#{javascript:sessionScope.selectedStartDate}"
    value="#{sessionScope.selectedStartDate}">
    <xp:this.converter>
        <xp:convertDateTime type="date"
            dateStyle="full">
        </xp:convertDateTime>
    </xp:this.converter>
</xe:djDateTextBox>
<xe:djDateTextBox
    id="EndDate"
    defaultValue="#{javascript:sessionScope.selectedEndDate}"
    value="#{sessionScope.selectedEndDate}">
    <xp:this.converter>
        <xp:convertDateTime type="date"
            dateStyle="full">
        </xp:convertDateTime>
    </xp:this.converter>
</xe:djDateTextBox>

结束日期字段:

<xe:djDateTextBox
    id="StartDate"
    defaultValue="#{javascript:sessionScope.selectedStartDate}"
    value="#{sessionScope.selectedStartDate}">
    <xp:this.converter>
        <xp:convertDateTime type="date"
            dateStyle="full">
        </xp:convertDateTime>
    </xp:this.converter>
</xe:djDateTextBox>
<xe:djDateTextBox
    id="EndDate"
    defaultValue="#{javascript:sessionScope.selectedEndDate}"
    value="#{sessionScope.selectedEndDate}">
    <xp:this.converter>
        <xp:convertDateTime type="date"
            dateStyle="full">
        </xp:convertDateTime>
    </xp:this.converter>
</xe:djDateTextBox>

请注意,这些字段绑定到sessionScope变量

第三,将数据源添加到自定义控件:

<xp:this.data>
        <xp:dominoView var="view1" viewName="ByDeliveryDate"
            keysExactMatch="true">

            <xp:this.keys><![CDATA[#{javascript:try {
    if(sessionScope.selectedStartDate == null) return;
    if(sessionScope.selectedStartDate == "") return;
    if(sessionScope.selectedEndDate == null) return;
    if(sessionScope.selectedEndDate == "") return;

    var vDateRange = session.createDateRange(sessionScope.selectedStartDate, sessionScope.selectedEndDate);
    return [vDateRange]

}catch(e){
    print("view filter error: " + e.toString())
}}]]></xp:this.keys>
        </xp:dominoView>
</xp:this.data>

最后,添加一个只刷新视图的按钮:

print("queryOpen: opening date range view");
if(sessionScope.selectedDateRange == null){
    print("selectedDateRange is null")
}else{
    for (var s in sessionScope.selectedDateRange) print(s);
}
print("queryOpen: completed");
<xp:button value="Go" id="FirstColumnSearchButton"
    styleClass="lotusBtn goButton">
    <xp:eventHandler event="onclick"
        submit="false" refreshMode="partial" refreshId="viewHolder">
    </xp:eventHandler>
</xp:button>

如果需要,还可以添加“重置”按钮以将视图恢复到其原始状态:

<xp:button value="Reset"
    id="FirstColumnSearchResetButton">
    <xp:eventHandler event="onclick"
        submit="false" refreshMode="partial" refreshId="viewHolder">
        <xp:this.action><![CDATA[#{javascript:sessionScope.selectedStartDate = "";
sessionScope.selectedEndDate = "";}]]>
        </xp:this.action>
    </xp:eventHandler>
</xp:button>


请注意,它没有使用我在原始问题中发布的
DoDaterRangeSearch()
函数

为什么要使用向量?是否尝试将vDateRange直接保存到sessionScope.selecteDateRange?视图上的第一列是什么样子的,也就是说,有什么样的数据?日期时间值?串?我很惊讶它一开始就可以工作。视图的第一列是包含日期时间值的日期列。那么向量呢?您尝试过不使用向量吗?我使用向量是因为视图的keys属性需要向量。我将vDateRange直接保存到sessionScope中。在上述函数底部的第9行中选择了一个aterange变量。视图的第一列是包含日期时间值的日期列。我也很惊讶它能起作用!如果用户能够离开视图并返回视图,那就太好了!:)当你得到这个错误时,向量中有什么?