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.
source share