Vaadin code standards

Its been at least 12 years since I last used Vaadin, and wow, it has come a long way.

I am interested in how others standardise their Vaadin code. For example, you can apply styles in three different ways, the java api, the getElement().getStyle().set(), and also addClassName()

What approach do you use and why have you chosen that approach?

I did just find this thread, it answers many of my questions: Best practices for structuring Vaadin Flow code?

In that specific case, I would suggest using the highest level of abstraction that works for you. This has multiple benefits:

  • It’s easier to understand the intent behind the code. “Enable the ‘primary’ variant for this button” vs “Add this string to a list of of CSS class names” vs “Update the background color and the font color”.
  • It has fewer risks of mistakes due to typos when you’re using built-in constants instead of typing out string values.
  • It is more future proof since the exact mechanism for how a button is made as primary could be changed in the future and it’s then more likely that the concept of a “theme variant” still works whereas low-level mechanisms might be changed.

You can also find a similar perspective with a different example in java - Vaadin Flow: Difference between Component and Element - Stack Overflow.

1 Like