搜索视图时,如果没有结果,则显示消息

时间:2016-10-06 01:56:51

标签: xpages

我读了这个post 与我想问的非常相似。但是,我试图使用该帖子的解决方案解决我的问题,但没有成功。我意识到我不能在那篇文章中提问。所以我会在这里发布我的代码。 (请注意,如果不适合创建新帖子,请将其删除)

在应用程序中,用户可以搜索,当用户单击按钮时,它会将用户重定向到结果页面。

在结果页面中,有一个计算字段和一个视图。如果搜索后视图中没有结果,则计算字段用于显示消息。如果结果与用户的条件匹配,则视图将显示结果。

当结果与用户的选择匹配时,视图工作正常,但如果没有结果与用户的选择匹配,则只显示视图列标题。因此,我想使用计算字段来显示一条消息,通知用户执行了搜索功能而没有返回结果。否则,用户将不知道他们的搜索没有结果返回。

以下是结果页面的代码。

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:this.data>
    <xp:dominoDocument var="document1"></xp:dominoDocument>
</xp:this.data>

<xp:text escape="true" id="computedField1" style="margin-left:200.0px">     </xp:text>
<xp:br></xp:br>
<xp:viewPanel id="viewPanel4" viewStyle="width:600.0px;background- color:rgb(255,255,255);margin-left:200.0px" rows="15">
    <xp:this.data>
        <xp:dominoView var="view4"
            viewName="OfficerDepLoc">
            <xp:this.search><![CDATA[#{javascript:var qstring= "";
if ((sessionScope.officerSearch != null && sessionScope.officerSearch != "")|| (sessionScope.depSearch != null && sessionScope.depSearch != "")|| (sessionScope.locSearch != null && sessionScope.locSearch !=""))
{   
    qstring = " ( FIELD officer contains " + sessionScope.officerSearch  + " & FIELD department contains" + sessionScope.depSearch + "& FIELD location contains" + sessionScope.locSearch + ")";
}
var db:NotesDatabase = session.getDatabase("",  "myapplication.nsf", false)
var dc:NotesDocumentCollection = db.getAllDocuments();
if (dc.getCount() == 0) 
{
    qstring =   getComponent("computedField1").setValue("After search, there is no record found");
}

return qstring;
}]]></xp:this.search>
        </xp:dominoView>
    </xp:this.data>
    <xp:viewColumn columnName="Officer" id="viewColumn11">
        <xp:viewColumnHeader value="officer " id="viewColumnHeader11" sortable="true">
        </xp:viewColumnHeader>
    </xp:viewColumn>
    <xp:viewColumn columnName="Department" id="viewColumn12">
        <xp:viewColumnHeader value="department" id="viewColumnHeader12" sortable="true">
        </xp:viewColumnHeader>
    </xp:viewColumn>
    <xp:viewColumn columnName="Location" id="viewColumn13">
        <xp:viewColumnHeader value="location" id="viewColumnHeader13" sortable="true">
        </xp:viewColumnHeader>
    </xp:viewColumn>
    <xp:this.facets>

        <xp:pager partialRefresh="true" layout="Previous Group Next" xp:key="footerPager" id="pager5">
        </xp:pager>
    </xp:this.facets></xp:viewPanel>
</xp:view>    

当我测试页面时,我注意到如果搜索没有结果,视图不会触发计算字段来显示消息。

我还尝试将此代码放到计算字段中以打算显示消息,但它什么也没显示。

var db:NotesDatabase = session.getDatabase("",  "myapplication.nsf", false)
var dc:NotesDocumentCollection = db.getAllDocuments();
if (dc.getCount() == 0) 
{
    qstring =   getComponent("computedField1").setValue("After search, there is no record found");
}

所以我想知道如果搜索没有结果,如何显示消息?非常感谢。

1 个答案:

答案 0 :(得分:2)

可能是这样的吗?

<xp:panel id="refreshPanel">
    <xp:viewPanel id="viewPanel4" rendered="getComponent("viewPanel4").getRowCount()>0">
    viewpanel columns
    </xp:viewPanel>
    <xp:panel id="noentriesPanel" rendered="getComponent("viewPanel4").getRowCount()==0">
    text no entries
    </xp:panel>
    </xp:panel>
相关问题