Problem when ordering information that is in an array! Javaweb

Asked

Viewed 18 times

0

I’m making a system to train but I can’t solve a problem, I have a page where I download registered items and it has a quantity field, but after user type there the system is only reading 1 time and adding in the orders all with quantity 1.

Follows code from html:

    <!--  escolher a navbar a ser carregada da pasta de scripts -->
    <script src="scripts/navbarGerente.js"></script>

        <form id="form" action="receberDadosIncluirItensVenda.jsp"  method="POST">
        <%
            String cpf = request.getParameter("id");
            Loja l = new Loja();
            List<Loja> vendas = l.consultarVendaLista(cpf);
            
            Cliente c = new Cliente();
            c = c.consultarCliente(cpf);
            
            Produto produto = new Produto();
            List<Produto> produtos = produto.consultarTodosProdutosDisponiveis();
            String srcImagem;
        %> 
        
        <div>
            <label>Ola <%out.write(c.getNome());%></label> <br>
            <input type="text" name="cpfcliente" id="cpfcliente" value="<%out.write(cpf);%>" readonly=true >
            <%for (Loja loja : vendas) { %>
            <label>Numero do Pedido:</label>
            <input type="text" name="idvenda" id="idvenda" value="<% out.write(""+loja.getIdVenda());%>" readonly=true>
           
        </div>
        
        <table class="table table-striped table-bordered table-light table-hover">
            <thead class="thead-primary">
            <th>Codigo Produto</th>
            <th>Foto</th>
            <th>Descrição</th>
            <th>Quantidade</th>
            <th>Preço</th>
            </thead>

            <tbody>

                <%    
                    Integer i = 0;
                    
                    while (i < produtos.size()) {  //enquanto houver prox elemento
                        for (Produto p : produtos) {
                         srcImagem = "imagens/produto_" + produtos.get(i).getIdProduto() + ".png";%>
                <tr>
                    <!-- caso for um dado numerico, utilizar duas aspas duplas 
                    ex: out.write("" + dado); -->
                    <td><% out.write("" + produtos.get(i).getIdProduto());%></td>
                    <input type="text" name="idProduto" id="idProduto" value="<% out.write("" + produtos.get(i).getIdProduto());%>" readonly=true hidden="true">
                    <td><img src="<%=srcImagem%>" style="height:160px"></td>
                    <td><% out.write(produtos.get(i).getDescricaoProduto());%></td>
                    <td><input type="text" name="quantidadeproduto"   id="quantidadeproduto" value="0" onkeypress="return onlyNumberKey(event)" class="form-control"></td>
                    <td><% out.write("R$" + p.getValorProduto());%></td>
                    <input type="text" name="valorProduto" id="valorProduto" value="<% out.write("" + produtos.get(i).getValorProduto());%>" readonly=true hidden="true">
                        
                </tr> 



                <!-- caso um for seja utilizado ali em cima para percorrer os dados na tabela
                tirar o comentario abaixo que fecha o for -->
                <!-- final do conteudo de cada elemento -->
                <% i++; %>
                <%}%>  <!-- final do for-loop -->
                <%}%>  <!-- final do while-loop -->
                <%}%>
                 
            </tbody>
        </table>
    <button name="botaoEnviar" id="botaoEnviar" type="submit"  class="btn btn-primary">Comprar</button>
    </form>

-------------when user clicks to buy his form send to this code <% String idvenda = request.getParameter("idvenda"); Boolean status = false; Store l = new Store(); List sales = l.teste(Integer.parseint(idvenda)); for (store : sales) { String Cpf = store.getIdCpf(); int id = store.getIdVenda();

 Produto produto = new Produto();
 List<Produto> produtos = produto.consultarTodosProdutosDisponiveis();
 Integer i = 0;
 while (i < produtos.size()) {
 for (Produto p : produtos) {
          l.setIdVenda(id);
          l.setIdCpf(cpf);
          int quantidadeProduto = 0;
          l.setIdProduto(p.getIdProduto());
          quantidadeProduto = Integer.parseInt(request.getParameter ("quantidadeproduto"));
          l.setQuantidade(quantidadeProduto);
          float valor = p.getValorProduto();
          if (quantidadeProduto >= 1 ){
               if (l.incluirItensNoPedido()){
                     status=true;
                     } else {
                             status=false;
                       }
          } 
         i++;    
        }
    }
    }

%>

If anyone can help I’m grateful!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.