I have a PrimeFaces p:dataTable with a lot of columns include a simple number input and 1 update button, and I want to update the specific row with the inserted value.
<p:dataTable var="book" value="#{bookController.books}">
<p:column headerText="Id">
<h:outputText value="#{book.id}" />
</p:column>
<p:column headerText="Quantity">
<h:outputText value="#{book.quantity}" />
</p:column>
<p:column headerText="Wanted Quantity">
<p:spinner value="#{bookController.quantities[book.id]}" max="#{book.quantity}"
size="10" min="0" />
</p:column>
<p:column headerText="Add to Cart">
<p:commandButton action="#{bookController.buy(book.id)}" value="add"/>
</p:column>
</p:dataTable>
and the bean is:
public class BookController {
private Map<Integer, Integer> quantities = new HashMap<>();
public void buy(Integer bookId) {
System.out.println(quantities.get(bookId)); //quantities is empty
}
public Map<Integer, Integer> getQuantities() {
return quantities;
}
public void setQuantities(Map<Integer, Integer> quantities) {
this.quantities = quantities;
}
}
I tried to send the value itself, and bind it to a map with no success.
What else can I do in order to to get the cell's value of the specific row?