How to iterate a HashMap with primefaces selectable datatable

大城市里の小女人 提交于 2019-11-29 15:44:39

Your problem is here:

<ui:repeat ...>
    <p:dataTable ... widgetVar="chatTableWV">
       <p:ajax ... oncomplete="chatTableWV.unselectAllRows();">

Multiple data tables are been assigned exactly the same widgetVar name in JavaScript scope. In effects, the following JavaScript code is generated:

window['chatTableWV'] = new Widget(tableElement1);
window['chatTableWV'] = new Widget(tableElement2);
window['chatTableWV'] = new Widget(tableElement3);
// ...

Basically, every iteration overrides the last object assigned to the declared widgetVar name until it ends up referencing the last one. All widgets expect of the last one are basically unavailable, causing them to not be functional anymore as to row selection.

Fix it accordingly by giving them each an unique widgetVar. You could use the iteration index of <ui:repeat> for this.

<ui:repeat ... varStatus="loop">
    <p:dataTable ... widgetVar="chatTableWV_#{loop.index}">
       <p:ajax ... oncomplete="chatTableWV_#{loop.index}.unselectAllRows();">

This way the following JavaScript code is generated:

window['chatTableWV_0'] = new Widget(tableElement1);
window['chatTableWV_1'] = new Widget(tableElement2);
window['chatTableWV_2'] = new Widget(tableElement3);
// ...

And finally PrimeFaces widget manager can find them all.

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