Vaadin 总和计算

问题描述

enter image description here

我无法添加字段,我已经尝试对代码进行多次修改,但没有任何效果

我当前的代码是用于字段总和的代码

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));

        });

解决方法

要计算所有头寸的总和,请在 txtAmount.addValueChangeListener 块中设置此代码段:

Double sum = listaVendas.stream().mapToDouble(product -> product.getPrice() * product.getQuantity()).sum(); 

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...