Show non editable calculated fields on a Form

Hi, vaadin user for 2 days now :slight_smile:

I’m trying to create a form for one of my entity classes. Beside the usual fields, this class has 2 methods that make some basic calculations. I would like to show the value of this methods on the form as the user fills the other fields. I tried to add a readonly text field but vaadin does not alow me to change it’s value programaticaly as I would expect based on my experience with other tools.

What’s the best aproach to solve this problem?

Thank you.

Welcome to Vaadin! :slight_smile:

I’m guessing that you got your calculations triggered and updated when new values are entered? (Otherwise see Field.setImmediate() and Property.ValueChangeListener)

If you’re looking for a Field that can be updated programmatically, but not through the UI, you’re probably looking for the Field.setEnabled(false). This will show a grayed-out field that cannot be changed in the UI, but you can change it’s value programmatically.

Another, perhaps better looking, way would be to use Labels to represent information that cannot be changed by the user. Labels have both captions and values, so they behave pretty much like TextFields (without the “box” or editing possibilities).


Labels is exactly what I need. I Didn’t know they could have values as well. Thanks a lot.