How-To

Using PMOs in Layouts

This section assumes that you are familiar with the usage of PMOs (Presentation Model Object (PMO)).

In the tutorial, we integrated PMOs using the class AbstractPage. This class conveniently integrates with PMOs because it provides a method addSection that converts any PMO into a Vaadin Component. Yet, if you want to use Vaadin layouts such as VerticalLayout or HorizontalLayout instead, you can refer to the example code below.

SearchSectionPmo.java
public class PartnerView extends VerticalLayout {

    private static final long serialVersionUID = 1L;

    private final BindingManager bindingManager = new DefaultBindingManager();

    private final Partner partner;

    public PartnerView(Partner partner) {
        this.partner = partner;

        // elements that are always visible can be instantiated in the constructor
        createContent();
    }

    public void createContent() {
        add(VaadinUiCreator.createComponent(
                                            new PartnerSectionPmo(partner),
                                            bindingManager.getContext(this.getClass())));
    }

}

The main difference between using either AbstractPage or a Vaadin layout is that for the latter we have to convert the PMOs to Vaadin components ourselves. Therefore, we use VaadinUiCreator to handle the conversion. Finally, we add the component to the layout using the add method.

Remember that an AbstractPage had to be initialised by calling init or else the component was not visualised at all. The same would hold for our example implementation above if we didn’t call the createContent method within the constructor. This is the preferred way of initialising UI components that persist throughout the entire life cycle.