Docs

Documentation versions (currently viewingVaadin 7)

You are viewing documentation for an older Vaadin version. View latest documentation

Interfaces and Abstractions

Vaadin user interface components are built on a skeleton of interfaces and abstract classes that define and implement the features common to all components and the basic logic how the component states are serialized between the server and the client.

This section gives details on the basic component interfaces and abstractions. The layout and other component container abstractions are described in "Managing Layout". The interfaces that define the Vaadin data model are described in "Binding Components to Data".

component abstractions hi
Component Interfaces and Abstractions

All components also implement the Paintable interface, which is used for serializing ("painting") the components to the client, and the reverse VariableOwner interface, which is needed for deserializing component state or user interaction from the client.

In addition to the interfaces defined within the Vaadin framework, all components implement the java.io.Serializable interface to allow serialization. Serialization is needed in many clustering and cloud computing solutions.

Component Interface

The Component interface is paired with the AbstractComponent class, which implements all the methods defined in the interface.

Component Tree Management

Components are laid out in the user interface hierarchically. The layout is managed by layout components, or more generally components that implement the ComponentContainer interface. Such a container is the parent of the contained components.

The getParent() method allows retrieving the parent component of a component. While there is a setParent(), you rarely need it as you usually add components with the addComponent() method of the ComponentContainer interface, which automatically sets the parent.

A component does not know its parent when the component is still being created, so you can not refer to the parent in the constructor with getParent().

Attaching a component to an UI triggers a call to its attach() method. Correspondingly, removing a component from a container triggers calling the detach() method. If the parent of an added component is already connected to the UI, the attach() is called immediately from setParent().

public class AttachExample extends CustomComponent {
    public AttachExample() {
    }

    @Override
    public void attach() {
        super.attach(); // Must call.

        // Now we know who ultimately owns us.
        ClassResource r = new ClassResource("smiley.jpg");
        Image image = new Image("Image:", r);
        setCompositionRoot(image);
    }
}

The attachment logic is implemented in AbstractComponent, as described in AbstractComponent.

AbstractComponent

AbstractComponent is the base class for all user interface components. It is the (only) implementation of the Component interface, implementing all the methods defined in the interface.

AbstractComponent has a single abstract method, getTag(), which returns the serialization identifier of a particular component class. It needs to be implemented when (and only when) creating entirely new components. AbstractComponent manages much of the serialization of component states between the client and the server. Creation of new components and serialization is described in "Integrating with the Server-Side".