Creating a Component Using Existing Components
Div
Label
One option would be to create the component by extending Div
but that would expose all Div
API like add(Component)
to the user. To avoid this, the component can be based on a :
A Composite will automatically create the root component, specified using generics (Composite<Div>
) and make it available through getContent(). In the constructor you only need to create the other components and add them to the root Div
. The value is set using setValue
in the Input
component.
To make the component easier to use, you can add an API for getting and setting the value and the label text by delegating to the Input
and Label
components:
Java
public String getValue() {
return input.getValue();
}
input.setValue(value);
}
public String getLabel() {
return label.getText();
}
public void setLabel(String labelText) {
label.setText(labelText);
}
The public API of TextField only contains the defined methods in addition to the few generic methods defined in the interface.
Tip | Using Components instead of Elements do not introduce overhead in the browser. |