I have an <ui:repeat>
with <ui:inputText>
:
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
template="./templates/masterLayout.xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<ui:define name="content">
<ui:repeat value="#{genproducts.dbList()}" var="itemsBuying">
<div class="indproduct">
<p class="center">#{itemsBuying.name}</p>
<div class="center">
<h:form style="margin-left: auto; margin-right: auto;">
<h:inputText value="#{itemsBuying.amount}" />
<h:commandLink action="#{shoppingCart.addToCart(itemsBuying)}" value="add" />
</h:form>
</div>
</div>
</ui:repeat>
</ui:define>
</ui:composition>
This is the #{genproducts}
backing bean:
@ManagedBean(name = "genproducts")
@ViewScoped
public class Genproducts{
public List<Product> dbList() throws SQLException {
List<Product> list = new ArrayList<>();
...
return list;
}
}
This is the Product
entity:
@ManagedBean(name = "product")
@RequestScoped
public class Product {
private int amount;
public int getAmount() {
return amount;
}
public void setAmount(int amount) {
this.amount = amount;
}
}
In my case, there are four products from dbList()
method. For the first three products, when I input a different value, the default value appears in action method. Only for the last product, it works as expected.
How is this caused and how can I solve it?