Beginner here. I have a simple pojo (Pedido
) with one property (referencia
) besides the id.
Using the form below, I can change pedido.referencia
through the Input Text.
editListPedidoBean.salvar
simply prints my List<Pedido>
, and I can see that the value I typed into the InputText is there.
<h:form>
<ui:repeat value="#{editListPedidoBean.listaPedidos}" var="pedido">
<h:outputLabel value="#{pedido.id}" />
<h:inputText value="#{pedido.referencia}" />
<h:commandButton value="salvar" action="#{editListPedidoBean.salvar}" />
<br />
</ui:repeat>
</h:form>
However, using a dataTable
, the value I type into the Input Text is not passed through to my backing bean. editListPedidoBean.salvar
prints the list wiith referencia
's old value.
<h:form>
<h:dataTable value="#{editListPedidoBean.listaPedidos}" var="pedido">
<h:column>
<h:outputLabel value="#{pedido.id}" />
</h:column>
<h:column>
<h:inputText value="#{pedido.referencia}" />
</h:column>
<h:column>
<h:commandButton value="salvar"
action="#{editListPedidoBean.salvar}" />
</h:column>
</h:dataTable>
</h:form>
How can I effectively bind a property in my bean to a field in a dataTable?
EDIT: Here's my bean:
package pedido;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.enterprise.inject.Model;
import javax.inject.Inject;
@Model
public class EditListPedidoBean implements Serializable {
private List<Pedido> listaPedidos = new ArrayList<>();
@Inject
EditListPedidoDao dao;
public List<Pedido> getListaPedidos() {
listaPedidos = dao.getListaPedidos();
return listaPedidos;
}
public void setListaPedidos(List<Pedido> listaPedidos) {
this.listaPedidos = listaPedidos;
}
public String salvar() {
System.out.println(listaPedidos);//I'm just printing out the list to see if my bean can 'see' the changes made in the InputText before I try to persist it.
return null;
}
}