Search code examples
xpages

Need to reload an XPage after a few seconds


I am trying to get an XPage to reload after 1 second but can't figure out the code to do it. Does anyone have an example on how to do this in XPages?


Solution

  • Use JavaScript's setTimeout() function in Client Side JavaScript code block <xp:scriptBlock to execute a reload after a second (1000 ms):

    <?xml version="1.0" encoding="UTF-8"?>
    <xp:view xmlns:xp="http://www.ibm.com/xsp/core">
        <xp:scriptBlock id="scriptBlockReload">
            <xp:this.value>
            <![CDATA[
                setTimeout(function() {
                     location.reload();
                }, 1000)
            ]]>
            </xp:this.value>
        </xp:scriptBlock>
        <xp:text escape="true" id="computedField1">
            <xp:this.value><![CDATA[#{javascript:new Date().getTime()}]]></xp:this.value>
        </xp:text>
    </xp:view>
    

    In case you just want to refresh a part of your XPage instead of reloading it completely you can replace

    location.reload();
    

    with

    XSP.partialRefreshGet("#{id:computedField1}", {})
    

    It will refresh computedField1 once after a second. It is up to you what kind of id you specify. It could be the id of a panel which includes several or even all components of your XPage.