Note that there are some explanatory texts on larger screens.

plurals
  1. POPrimeFaces: DataTable multiple selection not working
    primarykey
    data
    text
    <p>I don't seem to get multiple selection in PrimeFaces dataTables working.</p> <p>I'm trying to implement a list of clients (dataList) and show their respective bookings in nested dataTables with a possibility to select multiple bookings for billing:</p> <pre><code>&lt;p:dataList value="#{clientController.allClients}" var="client"&gt; &lt;p:column&gt; &lt;p:dataTable value='#{client.bookingsDataModel}' var='item' selection="#{client.bookingsToBill}"&gt; &lt;p:column selectionMode="multiple" /&gt; &lt;/p:dataTable&gt; &lt;/p:column&gt; &lt;/p:dataList&gt; </code></pre> <p>My controller and backing bean classes:</p> <pre><code>public class ClientController { public List&lt;Client&gt; getAllClients() { return clients; } } public class Client { private List&lt;Booking&gt; bookings; private Booking[] bookingsToBill; public LeistungDataModel getBookingsDataModel() { return new BookingsDataModel(bookings); } public Booking[] getBookingsToBill() { return bookingsToBill; } public void setBookingsToBill(Booking[] bookingsToBill) { this.bookingsToBill = bookingsToBill; } } </code></pre> <p>The data model class:</p> <pre><code>public class BookingsDataModel extends ListDataModel&lt;Booking&gt; implements SelectableDataModel&lt;Booking&gt; { public BookingsDataModel(List&lt;Booking&gt; data) { super(data); } @Override public Booking getRowData(String rowKey) { List&lt;Booking&gt; bookings = (List&lt;Booking&gt;) 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(); } } </code></pre> <p>The browser posts the following data to the server, when I submit the form with my selections: </p> <pre><code>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: </code></pre> <p>Also, I found during debugging that the <code>getRowData</code> method of the <code>BookingsDataModel</code> returns the correct <code>Booking</code> objects (the selected ones).</p> <p>However, always empty arrays are passed to the <code>setBookingsToBill</code> of my <code>Client</code> objects. What could be going wrong here?</p> <hr> <p><strong>Update:</strong></p> <p>An empty array is only passed the first <code>Client</code> objects - it doesn't matter if a booking has been selected or not. All other <code>Client</code> objects' <code>setBookingsToBill</code> methods are called with a parameter value of <code>null</code>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload