Does view.postscript() allow you to call functions loaded as output scripts?

强颜欢笑 提交于 2020-01-17 01:15:18

问题


I am using <xpScriptBlock> to store the contents of two rather long client side functions that loads an ExtJS grid. I can call the function using clientside javascript just fine.

I discovered that I need to show a different grid based on a condition in the underlining document. To reference the backend I moved the code to serverside and then tried to call the grid using view.postScript. This does not work and is the basis of my question.

Is this approach even possible? I do not wish to put all the code into the event. The functions are quite long and better kept in a script block for readability and maintainability. The functions are definitely loaded in the client, as I can manually load them using the firebug console. Perhaps I am missing something simple so I wanted to ask before changing my approach.

var typePO = document1.getItemValueString("typePO");
if(typePO == "AFS"){
    view.postScript("loadGridAFS();")
} else {
    view.postScript("loadGridOther();")
}

This code is in the serverside onClientLoad event of a panel. I have tried adding the 'return' keyword and it makes no difference.

UPDATE: I can't even get simple alerts to work using view.postscript(). Does this method only work in certain types of events in SSJS???


回答1:


After some experimenting using a simple alert I can say that view.postScript() does NOT work everywhere.

For a test, I put the same code in an six event of the xpage. Here is an example of the code I used: view.postScript("alert('onClientLoad');"); I just changed the message to match the event.

Here are the results:

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

I haven't tried every available event out there, but the bottom line here is that you shouldn't count on view.postscript() to work everywhere. And if it does do nothing, try a simple alert first to see of the event supports view.postscript before questioning the client javascript code you are attempting to run.



来源:https://stackoverflow.com/questions/18408733/does-view-postscript-allow-you-to-call-functions-loaded-as-output-scripts

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