0

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?

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
Dvir
  • 301
  • 1
  • 2
  • 16
  • Does https://stackoverflow.com/questions/25339056/understanding-primefaces-process-update-and-jsf-fajax-execute-render-attributes help? – Kukeltje May 19 '19 at 08:30
  • actually not really....any other workarouds are welcome.... – Dvir May 19 '19 at 11:32
  • This is exactly why we built the Sheet component. I wanted to submit one cell at a time and not a whole datatable. Especially when a lot of data is involved: https://www.primefaces.org/showcase-ext/views/sheet.jsf – Melloware May 19 '19 at 12:01
  • Then actually do not know what your problem is... – Kukeltje May 19 '19 at 15:06
  • Could you turn it insideout? I mean, add an attribute to `Book` called `quantity` with setters and getters and in the spinner reference to this book's property. – Oscar Pérez May 21 '19 at 09:45

0 Answers0