PrimeFaces: Multiple Selection DataTable Doesn't Work

I don't seem to get multiple selections in PrimeFaces worksheets.

I am trying to implement a customer list (dataList) and show their respective orders in nested data tables with the ability to select multiple orders for billing:

<p:dataList value="#{clientController.allClients}" var="client"> <p:column> <p:dataTable value='#{client.bookingsDataModel}' var='item' selection="#{client.bookingsToBill}"> <p:column selectionMode="multiple" /> </p:dataTable> </p:column> </p:dataList> 

My controller and support for bean classes:

 public class ClientController { public List<Client> getAllClients() { return clients; } } public class Client { private List<Booking> bookings; private Booking[] bookingsToBill; public LeistungDataModel getBookingsDataModel() { return new BookingsDataModel(bookings); } public Booking[] getBookingsToBill() { return bookingsToBill; } public void setBookingsToBill(Booking[] bookingsToBill) { this.bookingsToBill = bookingsToBill; } } 

Data Model Class:

 public class BookingsDataModel extends ListDataModel<Booking> implements SelectableDataModel<Booking> { public BookingsDataModel(List<Booking> data) { super(data); } @Override public Booking getRowData(String rowKey) { List<Booking> bookings = (List<Booking>) getWrappedData(); for(Booking booking : bookings) { if(("booking_"+booking.getId().toString()).equals(rowKey)) { return booking; } } return null; } @Override public Object getRowKey(Booking booking) { return "booking_"+booking.getId().toString(); } } 

The browser sends the following data to the server when I submit the form with my selections:

 j_idt9%3Aj_idt13%3A0%3Aj_idt15_selection:booking_300,booking_301,booking_302 j_idt9%3Aj_idt13%3A1%3Aj_idt15_selection:booking_566,booking_567 j_idt9%3Aj_idt13%3A2%3Aj_idt15_selection: 

In addition, during debugging, I found that the getRowData BookingsDataModel method returns the correct Booking objects (selected).

However, always empty arrays are passed to setBookingsToBill from my Client objects. What could be wrong here?


Update:

An empty array passes only the first Client objects - it doesn’t matter if a reservation is selected or not. All other Client objects' setBookingsToBill are called with a null parameter value.

+4
source share
2 answers

Not really, if you want a checkbox selected using a checkbox, you should do it like jfs:

There is one example in the window that shows just that. It will create a column containing fields for the user to select. You can also do as you said using the p: dataTable attribute, however this will not lead to the creation of boxes, and the user will have to control + click to make multiple selections.

0
source

SelectionMode must be part of the <p:dataTable> .

Here is a link to a showcase with an example. http://www.primefaces.org/showcase/ui/datatableRowSelectionMultiple.jsf

-3
source

Source: https://habr.com/ru/post/1411081/


All Articles