2

Both the Book of Vaadin and the Vaadin training course recommend using acom.vaadin.ui.CustomComponent to contain a Layout.

I can understand this in pure theory, to encapsulate the contents without needlessly exposing a specific layout such as GridLayout or HorizontalLayout. Encapsulating has benefits of:

  • Encouraging de-coupling between classes
  • Makes it easier to change the layout without having to change the declarations in the outer class.

But in terms of practicality, I assume the rendering of a CustomComponent means extra HTML/CSS layout instructions such as perhaps an another div. The last thing Vaadin rendering needs is yet another layering of HTML structure.

I wonder if this might be old folklore. Perhaps using the visual composing tool in Eclipse accepts only CustomComponent objects rather than Layout objects? (Just a wild guess, I have no knowledge)

➤ Alternatively, why not just declare in the outer class a reference variable of type com.vaadin.ui.Layout to get the same encapsulation?

➤ Am I exaggerating the impact of adding a CustomComponent to Vaadin rendering?

➤ Is there some other benefit of CustomComponent which I’ve failed to perceive?

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154

2 Answers2

0

The main advantage of the CustomLayout is, that you can place your components inside HTML code which you otherwise can't generate via vaadin means.

If this adds more div/html as with native Layouts depends on the specific case.

We ususally use it only when a clean Vaadin only solution would introduce more components/div's or is not possible to implement.

The second idea is the separation of layout and logic, which can be implemented partially with this Layout. You just specify which components you have and then a UI designer (in theorie) could make your HTML code, with the correct blocks where your components will be placed.

In real life I do not find this a real advantage, since the whole CSS, sizing etc. is anyway done with vaadin.

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
André Schild
  • 4,592
  • 5
  • 28
  • 42
  • 1
    You misunderstood the question. I am asking about [CustomComponent](https://vaadin.com/api/com/vaadin/ui/CustomComponent.html) not [CustomLayout](https://vaadin.com/book/-/page/layout.customlayout.html). Hit that first link for The Book Of Vaadin for info. You gave a good answer but on the wrong question. I suggest you create your own Question and post this Answer. Doing so is encouraged on StackOverflow. – Basil Bourque Oct 01 '14 at 07:30
0

You can compose the content of a CustomComponent with the Visual Designer. This saves a lot of time in the development process

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
d2k2
  • 726
  • 8
  • 16