amounts / currency in UI

Hallo.

Where can I find a complete example program using amount fields euros?
I’m just a starter in developing vaadin but till now, I’m very impressed about this framework.
But my big problem are the amount fields (like Euro etc. for business applications).
I want to enter and display this fields like “1,00“ till “1.123.456,789-“.
A good and complete example will help my to learn more about developing professional application with vaadin.
Is there any example (without MaskedTextFields – because it doesn’t run at the moment in my installation. It’s my next step to test).

Thanks for you support
Walter

Hi Walter,

here is an example with a PropertyFormatter from my current project:


    private TextField createPriceLimitTextField(BigDecimal priceLimit) {
        TextField textField = new TextField();
        textField.setRequired(true);
        textField.setImmediate(true);
        textField.setRequiredError("ErrorMessage");
        textField.addValidator(new PriceValidator("ErrorMessage"), getLocale()));
        textField.setNullSettingAllowed(false);
        NumberFormat nf = DecimalFormat.getNumberInstance(getLocale());
        textField.setNullRepresentation(nf.format(BigDecimal.ZERO));
        textField.setPropertyDataSource(new PropertyFormatter(new ObjectProperty<BigDecimal>(priceLimit)) {
            
            @Override
            public Object parse(String formattedValue) throws Exception {
                NumberFormat nf = DecimalFormat.getNumberInstance(getLocale());
                return new BigDecimal(nf.parseObject(formattedValue).toString());
            }
            
            @Override
            public String format(Object value) {
                NumberFormat nf = DecimalFormat.getNumberInstance(getLocale());
                nf.setMinimumFractionDigits(2);
                nf.setMaximumFractionDigits(2);
                return nf.format(value);
            }
        });
        return textField;
    }

This method generates a TextField with a formated number in the locale-format. I hope, this is what you are looking for.

regards,
Pascal

Not really Vaadin related and your case might be just output, but in general
one should avoid floating point data types for currencies
.

The
Java tutorial
also echoes this:

Hallo Pascal,
hallo Henri.

Many thanks for your support. Now I have good information to go on and change this code (of course - now I know - not a good one) in my factory file.

public Field createField(Item item, Object propertyId, Component uiContext) {
if (“identifier”.equals(propertyId)) {

} else if (“taxRate3”.equals(propertyId)) {
final TextField tf = new TextField();
tf.setCaption(Protab.TAXRATE3);
tf.setMaxLength(6);
tf.setDescription(Util.getMessage(“protab.description.tax”));
tf.setNullRepresentation(“”);
tf.addValidator(new DoubleValidator(Util.getMessage(“protab.validator.tax”)));
tf.addListener(new BlurListener() {
@Override
public void blur(BlurEvent event) {
tf.isValid();
}
});
tf.setWidth(“40%”);
tf.setTabIndex(45);
return tf;

For that I need some time.
For starters like me, an example in the vaadin sampler library would be a good aid.
Walter

Note that if the TextField is immediate, your BlurListener should not be needed.

EDIT: See also e.g. the Form examples in the
book examples
application - not exactly what you are doing but might help.

Hello Henri.

Thanks for this new tip and the link for the “Book of Vaadin Examples”.
I knew it not yet. After the first run, I’m surprised again joyfully.
Walter

Hello.

Because I’m too green in developing professional Java applications. Of course I know that - for all, wenn I read some questions andm it answer.
Ok, it’s 20 years ago, I did development by myself - in a 4GL - before I switched to Project Management.
In the last months I read the vaadin book and learned a lot from the examples. My first Vaadin-applications run very well with MySql. So im very happy.

Only one thing I find a big disaster: “entering numeric values in TextFields and in European format” like “3,450 * 1.000,00 = 3.450,00”. All Examples –
also vaadins example TextField → “value type” works with the American format. But just these types of stable code (European amounts / currency) must be
in all commercial applications in Europe. Till now, my searching for complete code examples in the internet had no success.
I Dream of a field, that I have to initialize / format and what after that automaticly handles entering and displaying numeric values in European format -
because developing must by easier. I test a lot - but without any success. Is that also really a dream in Java?

So, if anyone has an small and complete vaadin source example – e.g. a calculator (+, - …) - I can load in my eclipse and learn how it can handle my problem,
please let me know.
best regards
Walter