How to do multiple selection in jsf or primefaces dataTable?

南楼画角 提交于 2020-01-05 11:43:25

问题


I want to try out building a simple grid that has a delete column, consisting of checkboxes, just like the usual one in email.

User can then tick the checkboxes, and press delete, and i can get all the checked records, and delete them one by one.

Im trying to find a way to achieve this, but so far im still in doubt.

These are what i have in mind, each with it's own implementation question, haha :

  1. How to get the checked row indexes ? Using actionlistener for each toggle on each checkbox ? (but how do i pass the clicked index to the actionlistener ?)
  2. Or is there a way where i can get all the grid model, and loop the data to find out which one is checked, just like swing ? (but how do i get the grid model in the jsf bean ?)
  3. Or perhaps i should bind them to a simple list that contains only the checkbox column data ? (but how do i bind each checkbox to the list using indexes ?)

Im currently using primefaces, but i think the JSF solution can also be applied to primefaces datatable.

Please share your thoughts on this !

Thank you !


回答1:


Isn't this example from Primefaces showcase exactly what you are looking for?

It looks that it is simply adding a column to the p:dataTable this way:

<p:dataTable var="item" value="#{yourBean.allElements}"  
             selection="#{yourBean.selectedElements}">
    <p:column selectionMode="multiple" />
    ... other columns
</p:dataTable>


来源:https://stackoverflow.com/questions/5563498/how-to-do-multiple-selection-in-jsf-or-primefaces-datatable

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