Skip to main content

Open Source Consultant, Software Developer and System Administrator

If you are interrested in hiring a consultant for the effective use of open source software on an enterprise grade, take a look around in the About section to see, what I have to offer.

Blog and snippets

Various snippets or code parts I found useful, so I keep them here for reference.

Generic Vaadin8 field for converted values

In Vaadin8 the conversion between the model data type and the field is done in the Binder. This prevents automatic mapping for the models as some manual step must be done beforehand. But since writing custom fields now is way more reasonable, here is a first draft for a generic converter field. Just provide the backing Field and an Converter.

https://gist.github.com/christoph-frick/947fec59cfd09f7140933b52102cc041

Null representation needed when using converters in Vaadin 8 binder

TextFields in Vaadin8 are no longer allowed to get a null set as value. This usually is no problem unless we use a Converter for the field binding. In that case a null value about to be bound will raise an assertion error. It also won't help if that field is bound with asRequired.

The solution in this case is to use withNullRepresentation before adding the Converter in the binding builder. This adds another converter at first, that turns null values into "something" so the real converter has to actually work.

See

https://github.com/christoph-frick/try-vaadin8/commit/8eee2ce6880b7a3dd4ce1526cf533ef356d3ec50

and

https://github.com/vaadin/framework/issues/8725

Trying out Vaadin 8

Started a repo to try out the new/changed stuff from Vaadin 8. Lessons learned so far:

  • Immediate on fields is gone. They are now immediate by default.
  • Converter on fields is gone. You convert either in the Binder or you have to write your own field.
  • Use the Binder builder as a builder (chain your calls) -- even if your e.g. Groovy gives you builderish behaviour with with.
  • The CallbackDataProvider is basically the same as the LazyContainer from Viritin.
  • Creating your own CustomField becomes easier, since you get some proper guidance on what to implement. Yet making that field properly propagate change events is still on you.
  • For a composite field it's easiest to build it up using again a Binder and delegate addValueChangeListener down to it.

The repository is here: https://github.com/christoph-frick/try-vaadin8