call partialRefreshGet from SSJS using view.PostScript

▼魔方 西西 提交于 2019-12-04 18:34:36

You can't use before view.postScript in the beforePageLoad. Try moving it to afterPageLoad or beforeRenderResponse. I recently ran across the same issue.

http://notesspeak.blogspot.com/2013/08/viewpostscript-only-works-for-certain.html

Here is a summary where you can use view.postScript():

  1. onClientLoad = nothing happens
  2. beforePageLoad = XSP error
  3. afterPageLoad = WORKS!
  4. afterRestoreView = nothing happens
  5. beforeRenderResponse = WORKS!
  6. afterRenderResponse = nothing happens

To know why this is happening, read Tim Tripcony's comment at the bottom of the blog post.

Just add a scriptblock to your XPage with the required partial refresh.

EDIT:

<xp:scriptBlock id="scriptBlock2" rendered="#{javascript:requestScope.doRefresh}">
    <xp:this.value><![CDATA[
       XSP.addOnLoad( function(){ XSP.partialRefreshGet('#{id:panelAll}') } );
   ]]>
   </xp:this.value>
</xp:scriptBlock>

In your beforePageLoad you then set the requestScope variable if required.

This answer might be a little too late, I hope it would be useful for someone.

So, the simple answer is to use the following SSJS to refresh another component: view.postScript("XSP.partialRefreshGet('#{id:Component ID}')")

However, I've had my share of trouble trying it, and as Tim Tripcony suggested, the code seems to be running too soon, while the browser is still receiving the 1st refresh, and it doesn't work. So I tried attaching it in an OnLoad event like so:

view.postScript("XSP.addOnLoad(function() {XSP.partialRefreshGet('#{id:Component ID}')})")

But that also didn't work. So I did it the old way and it worked by letting the script work in a different thread using setTimeout() like this:

view.postScript("setTimeout(function(){XSP.partialRefreshGet('#{id:Component ID}')}, 1)");

and it's working like a charm!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!