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, make the currency read-only and even alow the user to enter simple calculations like "(10+12)*1,2". 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
fixed ArithmeticException when entering a division with non-terminating decimal expansion (like 1/3)
- Released
- 2024-09-25
- Maturity
- BETA
- License
- Apache License 2.0
Compatibility
- Framework
- Vaadin 24+
- Vaadin 21+ in 1.0.2
- Vaadin 23+ in 2.0.0
- Browser
- N/A
MoneyField - Vaadin Add-on Directory
Field for entering JSR354 javax.money.MonetaryAmounts (including both amount and currency)MoneyField version 1.0.2
fixed NPE when clearing
MoneyField version 1.1.0
* added/improved javadoc
* fixed overflow exception on huge amounts
* added possible validation
* added possible theme-variants (e.g. alignment)
* updated to latest vaadin version (21.0.3)
MoneyField version 2.0.0
Added possibility for entering primitive calculations like (1,23+8,99) * 1,2 in amount field
Amount field is now formatted according to locale (including thousands-delimiter) based on ICU format (e.g. 9,87,654.32 for indian locale)
MoneyField version 2.1.9
updated dependencies, fixed bug when clearing the moneyfield
MoneyField version 2.2.0
Updated to support Vaadin 24.X
MoneyField version 2.2.1
fixed ArithmeticException when entering a division with non-terminating decimal expansion (like 1/3)