How to iterate a HashMap with primefaces selectable datatable

前端 未结 1 491
情话喂你
情话喂你 2020-12-21 07:10

I have tried different solutions but none is working in my case. I want all the rows in this datatable to be selectable. The problem seems to be the

相关标签:
1条回答
  • 2020-12-21 07:46

    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.

    0 讨论(0)
提交回复
热议问题