Solucionado (ver solução)
Solucionado
(ver solução)
1
resposta

Unable to find method [getQuantidade] with [1] parameters

jsp

threw exception [An exception occurred processing JSP page /WEB-INF/views/carrinho/itens.jsp at line 28

25:                     <c:forEach items="${carrinhoCompras.itens}" var="item">
26:                         <td>${item.produto.titulo}</td>
27:                         <td>${item.preco}</td>
28:                         <td><input type="text" id="quantidade" name="quantidade" value="${carrinhoCompras.getQuantidade(item)}"/></td>
29:                         <td>${carrinhoCompras.getTotal(item)}</td>
30:                     <form action="" method="post">
31:                         <td><button type="submit">Remover</button></td>

Stacktrace:] with root cause javax.el.MethodNotFoundException: Unable to find method [getQuantidade] with [1] parameters

CarrinhoCompras

@Component
@Scope(value = WebApplicationContext.SCOPE_SESSION)
public class CarrinhoCompras implements Serializable{

    private static final long serialVersionUID = 1L;


    private Map<CarrinhoItem, Integer> itens = new LinkedHashMap<CarrinhoItem, Integer>();

    public void add(CarrinhoItem item) {
        this.itens.put(item, getQuantidade(item) + 1);

    }

    private Integer getQuantidade(CarrinhoItem item) {
        if (!this.itens.containsKey(item)) {
            this.itens.put(item, 0);
        }
        return this.itens.get(item);
    }

    public Integer getQuantidade() {
        return this.itens.values().stream().reduce(0, (proximo, acumulador) -> proximo + acumulador);
    }

    public BigDecimal getTotal(CarrinhoItem item){
        return item.getTotal(getQuantidade(item));
    }

    public BigDecimal getTotal(){
        BigDecimal total = BigDecimal.ZERO;
        for (CarrinhoItem item : itens.keySet()) {
            total = total.add(getTotal(item));
        }
        return total;
    }

    public Collection<CarrinhoItem> getItens() {
        return itens.keySet();
    }

}

alguma ideia? agradeço!

1 resposta
solução!

Olá Milton!

Isso é porque seu método getQuantidade está como private. Ele não será acessado fora da sua classe. Tente mudar para public.

Bons estudos!

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software