Interface HasComponents
- All Superinterfaces:
HasElement,HasEnabled,Serializable
- All Known Subinterfaces:
FlexComponent,HasItemComponents<T>,HasItemsAndComponents<T>,HasOrderedComponents
- All Known Implementing Classes:
Abbr,AccordionPanel,Anchor,Article,Aside,Board,Card,CheckboxGroup,Code,ConfirmDialog,DescriptionList,DescriptionList.Description,DescriptionList.Term,Details,Dialog,Dialog.DialogFooter,Dialog.DialogHeader,Div,Emphasis,FieldSet,FieldSet.Legend,FlexLayout,Footer,FormLayout,FormLayout.FormItem,FormLayout.FormRow,GridMenuItem,H1,H2,H3,H4,H5,H6,Header,HorizontalLayout,HtmlContainer,HtmlObject,Image,ListBox,ListBoxBase,ListItem,Main,MenuItem,MenuItemBase,MultiSelectListBox,NativeButton,NativeDetails.Summary,NativeLabel,NativeTable,NativeTableBody,NativeTableCaption,NativeTableCell,NativeTableFooter,NativeTableHeader,NativeTableHeaderCell,NativeTableRow,Nav,Notification,OrderedList,Paragraph,Popover,Pre,RouterLink,Row,Section,Select,Span,Tab,UI,UnorderedList,UploadDropZone,VerticalLayout,WebComponentUI
Component in itself provides basic support for child components that
are manually added as children of an element belonging to the component. This
interface provides an explicit API for components that explicitly support
adding and removing arbitrary child components.
HasComponents is generally implemented by layouts or components whose
primary function is to host child components. It isn't, for example,
implemented by non-layout components such as fields.
The default implementations assume that children are attached to
HasElement.getElement(). Override all methods in this interface if the
components should be added to some other element.
- Since:
- 1.0
- Author:
- Vaadin Ltd
-
Method Summary
Modifier and TypeMethodDescriptiondefault voidAdds the given components as children of this component.default voidAdd the given text as a child of this component.default voidadd(Collection<Component> components) Adds the given components as children of this component.default voidaddComponentAsFirst(Component component) Adds the given component as the first child of this component.default voidaddComponentAtIndex(int index, Component component) Adds the given component as a child of this component at the specific index.default <T,S extends Signal<T>>
voidbindChildren(Signal<List<S>> list, SerializableFunction<S, Component> childFactory) Binds a listSignalto this component using a child component factory.default voidRemoves the given child components from this component.default voidremove(Collection<Component> components) Removes the given child components from this component.default voidRemoves all contents from this component, including child components, text content as well as child elements that have been added directly to this component using theElementAPI.Methods inherited from interface com.vaadin.flow.component.HasElement
getElementMethods inherited from interface com.vaadin.flow.component.HasEnabled
bindEnabled, isEnabled, setEnabled
-
Method Details
-
add
Adds the given components as children of this component.In case any of the specified components has already been added to another parent, it will be removed from there and added to this one.
- Parameters:
components- the components to add
-
add
Adds the given components as children of this component.In case any of the specified components has already been added to another parent, it will be removed from there and added to this one.
- Parameters:
components- the components to add
-
add
Add the given text as a child of this component.- Parameters:
text- the text to add, notnull
-
remove
Removes the given child components from this component.- Parameters:
components- the components to remove- Throws:
IllegalArgumentException- if there is a component whose nonnullparent is not this component
-
remove
Removes the given child components from this component.- Parameters:
components- the components to remove- Throws:
IllegalArgumentException- if there is a component whose nonnullparent is not this component
-
removeAll
default void removeAll()Removes all contents from this component, including child components, text content as well as child elements that have been added directly to this component using theElementAPI. It also removes the children added only at the client-side. -
addComponentAtIndex
Adds the given component as a child of this component at the specific index.In case the specified component has already been added to another parent, it will be removed from there and added to this one.
- Parameters:
index- the index, where the component will be added. The index must be non-negative and may not exceed the children countcomponent- the component to add, value should not be null
-
addComponentAsFirst
Adds the given component as the first child of this component.In case the specified component has already been added to another parent, it will be removed from there and added to this one.
- Parameters:
component- the component to add, value should not be null
-
bindChildren
default <T,S extends Signal<T>> void bindChildren(Signal<List<S>> list, SerializableFunction<S, Component> childFactory) Binds a listSignalto this component using a child component factory. Each itemSignalin the list corresponds to a child component within this component.This component is automatically updated to reflect the structure of the list. Changes to the list, such as additions, removals, or reordering, will update this component's children accordingly.
This component must not contain any children that are not part of the list. If this component has existing children when this method is called, or if it contains unrelated children after the list changes, an
IllegalStateExceptionwill be thrown.New child components are created using the provided
childFactoryfunction. This function takes aSignalfrom the list and returns a correspondingComponent. It shouldn't returnnull. TheSignalcan be further bound to the returned component as needed. Note thatchildFactoryis run inside aEffect, and thereforeSignal.get()calls makes effect re-run automatically on signal value change.Example of usage:
SharedListSignal<String> taskList = new SharedListSignal<>(String.class); UnorderedList component = new UnorderedList(); component.bindChildren(taskList, ListItem::new);
Note: The default implementation adds children directly to the component’s element using the Element API and does not invoke
add(Component...). Components that overrideaddor manage children indirectly must override this method to provide a suitable implementation or explicitly disable it.- Type Parameters:
T- the value type of theSignals in the listS- the type of theSignals in the list- Parameters:
list- list signal to bind to the parent, must not benullchildFactory- factory to create new component, must not benull- Throws:
IllegalStateException- thrown if this component isn't emptyBindingActiveException- thrown if a binding for children already exists- See Also:
-