开发者

How to get all the selected items in a table?

开发者 https://www.devze.com 2023-03-03 11:15 出处:网络
i have a problem with the datatable component. I want to create a datatable with checkbox like a multiple selection example on primefaces showcase. This is the code:

i have a problem with the datatable component. I want to create a datatable with checkbox like a multiple selection example on primefaces showcase. This is the code:

<p:dataTable id="ta开发者_Go百科ble_cats" value="#{fooBean.catsList}" var="cat" selectionMode="single"   selection="#{fooBean.selectedCatsToDelete}">
<p:column selectionMode="multiple">
    <f:facet name="header">Remove</f:facet>
</p:column>
<p:column>
    <f:facet name="header">Cat Name</f:facet>
        <h:outputText value="#{cat.name}" />
    </p:column></p:dataTable>

So, the problem is when a select an item. I don't know how to get all the selected items in the table. Can anyone help me with this problem?


They are all set in the property behind #{fooBean.selectedCatsToDelete} and they are thus accessible in any action/listener method which you have hooked to some command link/button.

E.g.

<p:commandButton value="Remove" action="#{bean.remove}" />

with

public void remove() {
    someService.remove(selectedCatsToDelete); // JSF has already put the selected items in selectedCatsToDelete.
}


It's not quite clear what your comment means "this example doesn't work". Are there any errors? Or is selectedCatsToDelete empty?

First guess would be the selectionMode="single" in your <p:dataTable> versus selectionMode="multiple" in the column.

Try to remove the attribute from your table tag.

0

精彩评论

暂无评论...
验证码 换一张
取 消