Dynamic Adding of Elements Using Vaadin

Hello all,

I have a set of templates, banner.html for example, that I’d like to add elemnts to dynamically. For instance, I want Vaadin to grab the template, check if user is signed in, then insert the user’s name inside

. Now this is doable using CustomLayout, however, it adds a new div, which messes up the styles I already have. Is there a way to insert data dynamically without adding more divs/wrappers?

Thanks!

Well, you could create your own parser and use a Label in HTML mode, but that solution is quite error-prone. It would also limit what you could put inside the template. The only component that behaves similarly to what you want is indeed CustomLayout.

Of course, you could create your own extension of CustomLayout with the API you need.

How would I be able to override Vaadin’s default behavior of wrapping Labels with divs if I were to implement my own extensino of CustomLayout? I couldn’t find were it’s originating from in the first place.

Thank you very much!

VCustomLayout is the client-side class that determines where components are inserted. You can try to override the placement there. Regarding individual components, you can’t really remove the wrapper div. Most of Vaadins style names depend on the wrapper, as does a lot of layouting code. In any case, the DIVs are built into each component separately, and I would not recommend for you to start rewriting those.

If you really want to get rid of the wrappers, you need to create custom widgets yourself that do what you need them to. Be aware, that even then, GWT kind of forces you to associate DIVs with widgets.

Vaadin is really great when you don’t need full control over the DOM. But if you do, like in your case, everything becomes quite different…