Hi Experts,
For one of my portlet i have used the addValueChangeListener listener and when value changes , it gets called two times all the time . Is there a way we could restrict this to once ?
Regards,
Nischal
Hi Experts,
For one of my portlet i have used the addValueChangeListener listener and when value changes , it gets called two times all the time . Is there a way we could restrict this to once ?
Regards,
Nischal
Hi Nischal,
We had a similar problem also.
Basically every time he page was refreshed a new listener was added, thus determining the action that is triggered by the listener to be executed multiple time.
What we did is to check if a listener with the same name already exists before adding it.
The code looks like this (and it is placed in a Script block on the page):
var toggleTabs = CAF.model("#{caf:cid('toggleTabs')}");
var booleanFlag= false;
if(toggleTabs){
for (var i = 0, l, listeners = toggleTabs.listValueChangeListeners(); l = listeners[i]; i++){
if(l.key.name=='myMethodThatDoesSomething'){
booleanFlag = true;
}
}
if(!booleanFlag){
toggleTabs.addValueChangeListener(myMethodThatDoesSomething);
}
}
function myMethodThatDoesSomething(){
//your desired code here
}
Also you can use Firebug or other similar tools (maybe Developer Tools- F12 if you are using IE) to check the listeners and other element attributes.
Hope it helps,
Vlad Turian
Hi Vlad,
I tried with the approach you have mentioned , but somehow when i go over the browser console i see that it states TypeError: togglebutton.listValueChangeListeners is not a function . Could you please let me know if i miss something here ?
Thank you in advancne.
Regards,
Nis
Hi Nischal,
For what element do you try to use the listValueChangeListeners?
I am using it successfully for (com.webMethods.caf.faces.component.toggle.html.)HtmlToggleTabs.
Please check the 8-2-SP1_CAF_JavaScript_Reference to see if this javascript function is available for your desired element.
At a first sight it seems that the element has to inherit from CAF.Input.Model to have the listValueChangeListeners.
Hope it helps,
Vlad Turian