MoneyField
Field for entering JSR354 javax.money.MonetaryAmounts (including both amount and currency)
MoneyField is a simple field for entering / displaying monetary amounts (amount and currency) bound to a JSR-354 javax.money.MonetaryAmount. The user can enter the amount and select the currency from a drop-down. Developers can select which currencies are available, pre-select a currency and make the currency read-only. The amount is formatted and rounded according to the locale of the UI.
Icon made by Freepik from Flaticon
Sample code
MoneyField moneyField = new MoneyField(); moneyField.setCurrency("EUR");
FastMoney money = FastMoney.of(100.99, "AED"); List<String> currencies = Arrays.asList("AED", "AFN", "ALL", "AMD", "ANG", "AOA", "ARS"); // see https://en.wikipedia.org/wiki/ISO_4217 MoneyField moneyField = new MoneyField(money, currencies); moneyField.setLabel("Amount in currencies starting with A"); moneyField.addThemeVariants(TextFieldVariant.LUMO_ALIGN_RIGHT);
MoneyField amount = new MoneyField("Amount"); Binder<Invoice> binder = new BeanValidationBinder<>(Invoice.class); binder.forField(amount).asRequired().bind(Invoice::getAmount, Invoice::setAmount); // alternatively: binder.bindInstanceFields(this);
MoneyField moneyField = new MoneyField("Amount", true);
MoneyField money = new MoneyField("Amount", "EUR"); money.setCurrencyReadOnly(true);
Links
Compatibility
Was this helpful? Need more help?
Leave a comment or a question below. You can also join
the chat on Discord or
ask questions on StackOverflow.
Version
added focus
- Released
- 2023-03-24
- Maturity
- BETA
- License
- Apache License 2.0
Compatibility
- Framework
- Vaadin 23+
- Vaadin 21+ in 1.1.0
- Browser
- N/A