我有一个PrimeFaces p:dataTable,其中有很多列,包括一个简单的数字输入和1个更新按钮,我想用插入的值更新特定的行。
<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>
bean是:
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;
}
}
我尝试发送值本身,并将其绑定到地图,但没有成功。
我还能做些什么才能获得特定行的单元格值?