Reputation: 6936
In my XPage I have an addOnLoad
written in my script block. But the thing is that it fires even during partial refresh which I don't want. For e.g. if I have a pager control on a data table then clicking on pages fires the addOnLoad
function. This happens with both dojo.addOnLoad
and XSP.addOnLoad
.
dojo.addOnLoad(function() {
console.log("addOnLoad");
});
This would print 'addOnLoad' every time a partial refresh takes place. I even tried to modify the code this way but no luck.
var addOnLoadFired = false;
dojo.addOnLoad(function() {
if (addOnLoadFired) {
return;
}
addOnLoadFired = true;
console.log("addOnLoad");
});
How can this be avoided?
Upvotes: 1
Views: 901
Reputation: 10485
When doing a partial refresh without specifying a refresh id, the whole XPage is refreshed. Same happens if you refresh the UIViewRoot element. In both cases this includes your output scriptblock, and that is why your addOnLoad event is fired over and over again.
A pager refreshs his parent component automatically. If your Pager is just added to your XPage, it will always refresh the UIViewRoot.
To fix your problem, you can embedd the dataTable and the pager in a xp:div element. Another idea is to check in the rendered property of your output script block if a partial refresh is executed.
EDIT: Check for partial refresh programmatically (SSJS):
var ajax = new com.ibm.xsp.ajax.AjaxUtil();
if( ajax.isAjaxPartialRefresh(facesContext) == true){
return "AJAX";
}else{
return "NOT AJAX!"
}
Upvotes: 5