Building a website in Vaadin

My journey went from ERP SAP consultant, to Outsystems certified low code developer. But low code failed at my Company. Then hands on dev experience with Thinkwise and Betty Blocks low code platforms. When low code failed at my Company I became JAVA developer (OCA and OCP), couple of years JSF, some Angular, every customer seemed to have another fancy platform. Oops, forgot to tell: one customer had a JAVA code generator built in Javascript, used for building web services. The thing is: the generated code was more scala than JAVA pure, nearly 100% functional programming ;-) Maintainers couldn’t get the hang of it and the whole thing was replaced by SpringBoot.

You know, frontend/backend team separation: I lived that. When I started JAVA Vaadin was already around, but nobody knew of it, no no no Angular and SpringBoot was the way! And if you complained about doing things double your were a sissy.

Anyway in my own time I searched for platforms that didn’t have the Outsystem-like Vendor lock in with HUGE subscriptions (that’s why it failed and you don’t even own your own code). For fun I built the same app we created in Outsytems low code with other platforms, to compare the effort, in my own time. So far I have done the same app in:

  • JSF (years ago)
  • JHipster (could have been so much more, JHIPSTER
  • Wappler Node low code-ish platform for dynamic websites and real apps
  • JMIX (the end result is pretty cool: lease contracts are signed on a tablet and the signed lease contract is then mailed as pdf, same level of nice as Outsystems)

Then, since JMIX uses Vaadin, and there is a free tier, I now have to try Vaadin, for the same app. But before doing so I try to brush up my frontend skills by creating a personal website. I must say I like it a lot to do everything in JAVA. I started with dynamic grids, but the “CSS String injections” drove me crazy, I took a step back and now I do everything with plain Layouts (and Lumo util) and it works very well, to get things nicely responsive. Love it so far!

1 Like

Your terminology sounds odd to me, which makes me thing that you are trying to do something wrong way. Thus I drop here couple of links to our document which covers how to style and customize Vaadin.

The generic styling / theme guidance is here

The theme can be easily customized with few global style properties, that define color palette, roundness, spacing and font.

And when you browse our Components documentation, each component has “Styling” sub-page

There you will see built-in style variants, custom properties and exposed parts you can easily use. I recommend to use them in this order, as built-in style variants can be easily activated with Java API.

Also one good rule of thumb with Vaadin is that design the page / application using Vaadin’s components, not by free hand. I.e. use the design system, do not fight against it.

Highest respect for you guys, but the link you are pointing to exactly illustrates my point of frustration, see below. It might very well be that it’s the ultimate way to go in the long run, but for now I park that stuff, and I have forbidden AI to do any more suggestions like that:

  • saveButton.getStyle().set(“–vaadin-button-background”, “green”);

For every alignment problem there seems to be another style string (“align” oops no, here it’s “justify”). If you make a typo? No feedback, just nothing happens. In stead I am trying to get away (as much as possible) with:

  • cardArea.addClassName(LumoUtility.Padding.Top.XLARGE);

So that I can actually see up front what the options are. Remember I just started, and this helps me. Also: combining Horizontal- and VerticalLayout combined with setFlexGrow() seems to work very well to make things as responsive as I need with a minimum of code.

Bas

1 Like

Thanks for the feedback! We are actually right now in the process of trying to figure out a better styling API.

Using style properties like --vaadin-button-background through the Java API is indeed awkward as you don’t get any autocompletion or such. Using them in stylesheets, as the document’s examples show, with an IDE with proper CSS support (like IntelliJ Ultimate) is a better experience.

LumoUtility constants are certainly easier to use in Java.

One of the things we are planning to do is to provide Java APIs for those theme and component style properties, so you could do something like cardArea.getStyle().setPadding(Lumo.Padding.Top.XLARGE); or cardArea.getStyle().setTextColor(Lumo.TextColor.WARNING) instead of relying on the classname API.

We’re also trying to make it possible to co-locate all (or at least 90%) of the CSS you might need with your Java code, so that you wouldn’t need to have it in a separate stylesheet, and provide a dedicated Java API for it. This might end up looking something along the lines of:

static final Style cardStyles = new Style()
  .setPadding(Lumo.Padding.Top.XLARGE)
  .setTextColor(Lumo.TextColor.WARNING)
  .setAlignItems(AlignItems.CENTER)
  .setJustifyContent(JustifyContent.START);
cardArea.applyStyles(cardStyles);

The above code would be “rendered” as a CSS style block in a generated stylesheet that’s automatically loaded.

You mentioned “align” and “justify” as being confusing, and those terms would probably be retained as we don’t want to rename native CSS keywords, as that would make it more difficult for coding agents and humans who know some CSS to use them.

That being said, I would be interested in hearing more details about the alignment problems you had?

Thanks for answering in detail Rolf, I know under the hood it is all CSS and I think I understand the tradeoffs and dilemmas. As for alignment problems: I don’t have any real problems so far. Love being able to do everything in JAVA!

Since I want my website to be responsive, I started with extending Div(), with a 12 column CSS grid, but after enough CSS Strings I decided to take a step back and simplify things using only the basic Layouts. Now I use a HorizontalLayout with 2 “spacers” left and right (as HLayouts) and a content area in the middle (as VLayout). This works just fine for me, with very few lines of code.

As for your suggestions on Style and applyStyle(), I thought about it and it looks really nice and efficient. Your example shows applying all styles in one run. Would it still be possible to apply one extra style? Because (as inexperienced frontender) I want to apply a specific style when I “bump to it” (like I want to have this button down-right).

Kind regards and thanks for answering,

Bas

Comment from a colleague:

I would except the API to be composable, and to be able to do this:

cardArea.applyStyles(cardStylesABC, cardStylesXYZ);

or

var newCardStyle = cardStyles.setPadding(Top.SMALL).and(cardStylesOther);

CSS is hugely extensive I noticed, I am diving a bit into it on W3Schools CSS. I am afraid I am surrendering a bit to the getStyle().set() way. It’s much easier with a CSS reference sitting in a browser tab. And in a way it is cool to have a standard interface directly from java to nearly all CSS commands. Saying this, I fully understand that CSS stylesheets are “company best practice”.

Some progressive insights for me:

  • All frameworks use the same basic CSS, so learning the basics is good investment
  • Apart from being evil, getStyle().set() is actually also very powerful
  • I kind of understand Vaadin doesn’t want to wrap a zillion CSS commands in java

Website development is going great, I have fun and good progress. It shows cards (articles with title/image/text) dynamically from a Springboot database (among other things). Everything is responsive and looks good on a phone too. Soon I will show my version 0.1 (kind of proof of concept) hopefully on my own www.iqthink.nl domain. Served from an Orange PI5 RK3588 mini pc the size of a pack of cigarettes ;-)

Check out version 0.1 of my responsive (well one page needs work) website built in Vaadin:

  • Version 0.1
  • Responsive design
  • SpringBoot with Sqlite database
  • On my own 10$ year domain with CaddyServer SSL
  • Running on an Orange Pi 5 minicomputer from my home

www.iqthink.nl

Next steps are admin page and Spring security. Love Vaadin so far!

Hello all! A little update on my hobby site for the ones interested:

  • Added an admin page, see iqthink.nl/admin (user admin/admin!#)
  • Admin can add (and delete) images to the image library in the form of a horizontally scrolling image bar
  • Admin can add/edit/delete articles via CrudUI component, articles are dynamically rendered as Cards
  • Articles contain header/image/text
  • Introduced a combobox to pick images from /upload folder (via a renderer images are displayed in combo and can be picked)
  • Introduced TinyMCE richtext editor in stead of LongText component
  • Secured the admin page with a minimal Spring Security setup
  • Site runs on a tiny RK3588 board
  • More details: see www,iqthink.nl

Totally love Vaadin!

1 Like

Cool!

Question about TinyMCE, are you using that though the old add-on or via own custom solution, free or paid tier?

I’m wondering because I have been lately moving to HugeRTE as the licensing change in TinyMCE was bit of a dirty trick couple of years ago. Doesn’t affect all apps, but many…

cheers,
matti

Hi Matti, as far as I am aware TinyMCE is free (team Parttio in de Vaadin addon dir) but on closer inspection there seem to be some limitations. Like the TinyMCE logo must be visible. For closed source commercial softare there is a license needed I think. Good point, maybe I should switch to HugeRTE too ;-)