I thought to myself, "no problem, I will just use view.postScript() and it will run fine." When I test the code, nothing happens. The script never runs, and there are no errors. I checked Firebug and the scripts loaded fine, as in I was able to launch them using the JavaScript console. At that point, I did some googling and didn't find all that much out there on view.postScript(). I found a few articles, but nothing that helped me with my problem.
I then turned to Stack Overflow. Sometimes, just the act of trying to write a question as clear as possible will cause me to think of the answer before I even post the question, but not this time though. I went ahead and posted this question.
After I posted I got to thinking that maybe it wasn't my logic, but just that the code was being ignored. I created a alert message using view.postScript and it still did not work. I then tried putting that alert in the afterRenderResponse event of the xpage, where I had some other code. Nothing happened there either. Frustrated, I then started putting the code in all the events, and to my surprise it worked some places and not others.
Basically, the view.postScript() method only works in certain events. I do not know why this is, but if I had to guess it has something to do with the JSF lifecycle.
I did some experimenting with the Xpage events and here is what I found.
- onClientLoad = nothing
- beforePageLoad = XSP error
- afterPageLoad = WORKS!
- afterRestoreView = nothing
- beforeRenderResponse = WORKS!
- afterRenderResponse = nothing
I can tell you that it doesn't work in the only Panel event, onClientLoad. I am pretty sure I have used it with onClick events before, so it does work there.