Question

I would like to create a dashboard to show 10 rows of record in a view and then, system will automatically to switch to next page after certain time. Isn't possible to set timer to automatically switch pager in next page in XPages? If yes, do you have any sample codes for reference? Thanks.

Was it helpful?

Solution

I created such a solution some time ago. Maybe it is helpful to you too.

In requestScope "rowsPerPage" you can define how many rows should visible per page and with requestScope "secondsPerPage" you define the number of seconds after it shall change the page. After arriving last page it starts again with first page.

<xp:this.beforeRenderResponse><![CDATA[#{javascript:
    requestScope.rowsPerPage = 4;
    requestScope.secondsPerPage = 2;
    if (viewScope.currentPage == null) {
        viewScope.put("currentPage", 1);
    } else {
        if (getComponent("viewPanel1").getRowCount() > viewScope.currentPage * requestScope.rowsPerPage) {
            viewScope.currentPage++;
            getComponent("viewPanel1").gotoNextPage();
        } else {
            viewScope.currentPage = 1;
            getComponent("viewPanel1").gotoFirstPage();
        }
    }
}]]></xp:this.beforeRenderResponse>
<xp:scriptBlock
    id="scriptBlockRefresh">
    <xp:this.value>
        <![CDATA[
            setInterval(function() {
                XSP.partialRefreshPost("#{id:refreshPanel}", {})
            }, #{requestScope.secondsPerPage} *1000)
        ]]>
    </xp:this.value>
</xp:scriptBlock>

<xp:panel
    id="refreshPanel">
    <xp:viewPanel
        rows="#{javascript:try {requestScope.rowsPerPage} catch(e) {30}}"
        id="viewPanel1"
        xp:key="facet1"
        viewStyle="width:40em">
        <xp:this.facets>
            <xp:pager
                partialRefresh="true"
                layout="Group"
                xp:key="headerPager"
                id="pager1"
                alwaysCalculateLast="true">
            </xp:pager>
        </xp:this.facets>
        <xp:this.data>
            <xp:dominoView
                ...>
            </xp:dominoView>
        </xp:this.data>
        <xp:viewColumn
            ...>
        </xp:viewColumn>
        <xp:viewColumn
            ...>
        </xp:viewColumn>
    </xp:viewPanel>
</xp:panel>

OTHER TIPS

I haven't tried it, but you would need to use CSJS to trigger a partial refresh using XSP.partialRefreshGet() after a pre-defined number of seconds, that couldn't be done server-side.

You could programmatically set the "first" property of the view, getting or (in the first instance) setting a viewScope variable. You'll need to ensure it's not updated multiple times during the page refresh, maybe by setting a requestScope variable and checking whether that's already been set.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top