0

enter image description here

I am not able to add the fields, I have already tried several modifications in the code, but nothing worked.

My current code is this for the sum of the fields:

txtAmount.addValueChangeListener(event -> {

            NumberFormat formatter = NumberFormat.getCurrencyInstance(new Locale("pt", "BR"));
            double totalValue= 0;

            try {
                totalValue = formatter.parse(txtUnitaryValue.getValue()).doubleValue() * txtQuantidade.getValue();
            } catch (ParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            txtTotalItemValue.setValue(formatter.format(totalValue));

            addValues= totalValue;
            fieldAddsValues.setValue(formatter.format(addValues));

        });
Shadow
  • 33,525
  • 10
  • 51
  • 64

1 Answers1

4

To calculate the sum of all positions set this snippet in the txtAmount.addValueChangeListener block:

Double sum = listaVendas.stream().mapToDouble(product -> product.getPrice() * product.getQuantity()).sum(); 
Twistleton
  • 2,735
  • 5
  • 26
  • 37