public class Composite extends AbstractComponent implements HasComponents
A composite is created by extending the Composite class and setting the
composition root component using setCompositionRoot(Component).
The composition root itself can contain more components. The advantage of wrapping it in a composite is that the details of the composition root, such as its public API, are hidden from the users of the composite.
A composite itself does not contribute to the DOM in any way (contrary to
CustomComponent which adds a <div> to the DOM.
HasComponents.ComponentAttachDetachNotifier, HasComponents.ComponentAttachEvent, HasComponents.ComponentAttachListener, HasComponents.ComponentDetachEvent, HasComponents.ComponentDetachListenerComponent.ErrorEvent, Component.Event, Component.Focusable, Component.ListenerClientConnector.AttachEvent, ClientConnector.AttachListener, ClientConnector.ConnectorErrorEvent, ClientConnector.DetachEvent, ClientConnector.DetachListenerSizeable.UnitDESIGN_ATTR_PLAIN_TEXTSIZE_UNDEFINED, UNITS_CM, UNITS_EM, UNITS_EX, UNITS_INCH, UNITS_MM, UNITS_PERCENTAGE, UNITS_PICAS, UNITS_PIXELS, UNITS_POINTS| Constructor and Description |
|---|
Composite()
Constructs a new empty composite.
|
Composite(AbstractComponent compositionRoot)
Constructs a new composite containing the given component.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addStyleName(String style)
Adds one or more style names to this component.
|
void |
beforeClientResponse(boolean initial)
Called before the shared state and RPC invocations are sent to the
client.
|
String |
getCaption()
Gets the caption of the component.
|
ErrorMessage |
getComponentError()
Gets the component's error message.
|
protected Component |
getCompositionRoot()
Returns the composition root.
|
String |
getDebugId() |
String |
getDescription()
Gets the components description, used in tooltips and can be displayed
directly in certain other components such as forms.
|
ErrorMessage |
getErrorMessage()
Gets the error message for this component.
|
float |
getHeight()
Gets the height of the object.
|
Sizeable.Unit |
getHeightUnits()
Gets the height property units.
|
Resource |
getIcon()
Gets the icon resource of the component.
|
String |
getId()
Gets currently set debug identifier.
|
String |
getPrimaryStyleName()
Gets the primary style name of the component.
|
protected CompositeState |
getState()
Returns the shared state bean with information to be sent from the server
to the client.
|
protected CompositeState |
getState(boolean markAsDirty)
Returns the shared state for this connector.
|
String |
getStyleName()
Gets all user-defined CSS style names of a component.
|
float |
getWidth()
Gets the width of the object.
|
Sizeable.Unit |
getWidthUnits()
Gets the width property units.
|
boolean |
isCaptionAsHtml()
Checks whether captions are rendered as HTML
|
boolean |
isEnabled()
Tests whether the component is enabled or not.
|
Iterator<Component> |
iterator()
Gets an iterator to the collection of contained components.
|
void |
removeStyleName(String style)
Removes one or more style names from component.
|
void |
setCaption(String caption)
Sets the caption of the component.
|
void |
setCaptionAsHtml(boolean captionAsHtml)
Sets whether the caption is rendered as HTML.
|
void |
setComponentError(ErrorMessage componentError)
Sets the component's error message.
|
protected void |
setCompositionRoot(Component compositionRoot)
Sets the component contained in the composite.
|
void |
setDebugId(String id) |
void |
setDescription(String description)
Sets the component's description.
|
void |
setDescription(String description,
ContentMode mode)
Sets the component's description using given content
mode. |
void |
setEnabled(boolean enabled)
Enables or disables the component.
|
void |
setHeight(float height,
Sizeable.Unit unit)
Sets the height of the object.
|
void |
setHeight(String height)
Sets the height of the component using String presentation.
|
void |
setHeightUndefined()
Clears any defined height.
|
void |
setIcon(Resource icon)
Sets the component's icon.
|
void |
setId(String id)
Adds an unique id for component that is used in the client-side for
testing purposes.
|
void |
setPrimaryStyleName(String style)
Changes the primary style name of the component.
|
void |
setSizeFull()
Sets the size to 100% x 100%.
|
void |
setSizeUndefined()
Clears any size settings.
|
void |
setStyleName(String style)
Sets one or more user-defined style names of the component, replacing any
previous user-defined styles.
|
void |
setStyleName(String style,
boolean add)
Adds or removes a style name.
|
void |
setWidth(float width,
Sizeable.Unit unit)
Sets the width of the object.
|
void |
setWidth(String width)
Sets the width of the component using String presentation.
|
void |
setWidthUndefined()
Clears any defined width.
|
addContextClickListener, addListener, addShortcutListener, attach, detach, findAncestor, fireComponentErrorEvent, fireComponentEvent, focus, getActionManager, getCustomAttributes, getData, getLocale, getParent, isConnectorEnabled, isOrHasAncestor, isReadOnly, isRequiredIndicatorVisible, isResponsive, isVisible, readDesign, removeContextClickListener, removeListener, removeShortcutListener, setData, setHeightFull, setLocale, setParent, setReadOnly, setRequiredIndicatorVisible, setResponsive, setVisible, setWidthFull, writeDesignaddAttachListener, addDetachListener, addExtension, addListener, addListener, addListener, addListener, addListener, addListener, addMethodInvocationToQueue, createState, encodeState, equals, fireEvent, getAllChildrenIterable, getConnectorId, getErrorHandler, getExtensions, getListeners, getResource, getRpcManager, getRpcProxy, getSession, getStateType, getUI, handleConnectorRequest, hashCode, hasListeners, isAttached, isThis, markAsDirty, markAsDirtyRecursive, registerRpc, registerRpc, removeAttachListener, removeDetachListener, removeExtension, removeListener, removeListener, removeListener, removeListener, removeListener, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler, setResource, updateDiffstateclone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitaddListener, addStyleNames, attach, getLocale, getParent, getUI, isVisible, readDesign, removeListener, removeStyleNames, setParent, setVisible, writeDesignaddAttachListener, addDetachListener, detach, encodeState, getErrorHandler, getExtensions, getRpcManager, getStateType, handleConnectorRequest, isAttached, isConnectorEnabled, markAsDirty, markAsDirtyRecursive, removeAttachListener, removeDetachListener, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandlergetConnectorIdsetHeightFull, setWidthFullforEach, spliteratorpublic Composite()
Use setCompositionRoot(Component) to define the contents of the
composite.
public Composite(AbstractComponent compositionRoot)
compositionRoot - the root of the composition component tree. It must not be
null.protected Component getCompositionRoot()
protected void setCompositionRoot(Component compositionRoot)
You must set the composition root to a non-null value before the component can be used. It cannot be changed.
compositionRoot - the root of the composition component tree.public Iterator<Component> iterator()
HasComponents
The iterator is typically unmodifiable, and calls to
Iterator.remove() throw an exception.
iterator in interface HasComponentsiterator in interface Iterable<Component>protected CompositeState getState()
AbstractComponentgetState in class AbstractComponentprotected CompositeState getState(boolean markAsDirty)
AbstractClientConnectorgetState in class AbstractComponentmarkAsDirty - true if the connector should automatically be marked dirty,
false otherwiseAbstractClientConnector.getState()public void beforeClientResponse(boolean initial)
ClientConnectorbeforeClientResponse in interface ClientConnectorbeforeClientResponse in class AbstractComponentinitial - true if the client-side connector will be created
and initialized after this method has been invoked.
false if there is already an initialized
client-side connector.public String getStyleName()
ComponentThe style names are returned only in the basic form in which they were added; each user-defined style name shows as two CSS style class names in the rendered HTML: one as it was given and one prefixed with the component-specific style name. Only the former is returned.
getStyleName in interface ComponentgetStyleName in class AbstractComponentComponent.setStyleName(String),
Component.addStyleName(String),
Component.removeStyleName(String)public void setStyleName(String style)
Component
Label label = new Label("This text has a lot of style");
label.setStyleName("myonestyle myotherstyle");
Each style name will occur in two versions: one as specified and one that
is prefixed with the style name of the component. For example, if you
have a Button component and give it "mystyle" style, the
component will have both "mystyle" and "v-button-mystyle"
styles. You could then style the component either with:
.myonestyle {background: blue;}
or
.v-button-myonestyle {background: blue;}
It is normally a good practice to use addStyleName() rather than this setter, as different software
abstraction layers can then add their own styles without accidentally
removing those defined in other layers.
setStyleName in interface ComponentsetStyleName in class AbstractComponentstyle - the new style or styles of the component as a space-separated
listComponent.getStyleName(),
Component.addStyleName(String),
Component.removeStyleName(String)public void setStyleName(String style, boolean add)
Componentadd parameter is true, the style name is added to the
component. If the add parameter is false, the style name is
removed from the component.
Functionally this is equivalent to using Component.addStyleName(String) or
Component.removeStyleName(String)
setStyleName in interface Componentstyle - the style name to be added or removedadd - true to add the given style, false
to remove itComponent.addStyleName(String),
Component.removeStyleName(String)public void addStyleName(String style)
Component
Label label = new Label("This text has style");
label.addStyleName("mystyle");
Each style name will occur in two versions: one as specified and one that
is prefixed with the style name of the component. For example, if you
have a Button component and give it "mystyle" style, the
component will have both "mystyle" and "v-button-mystyle"
styles. You could then style the component either with:
.mystyle {font-style: italic;}
or
.v-button-mystyle {font-style: italic;}
addStyleName in interface ComponentaddStyleName in class AbstractComponentstyle - the new style to be added to the componentComponent.getStyleName(),
Component.setStyleName(String),
Component.removeStyleName(String)public void removeStyleName(String style)
Component
The parameter must be a valid CSS style name. Only user-defined style
names added with addStyleName() or
setStyleName() can be removed; built-in
style names defined in Vaadin or GWT can not be removed.
removeStyleName in interface ComponentremoveStyleName in class AbstractComponentstyle - the style name or style names to be removedComponent.getStyleName(),
Component.setStyleName(String),
Component.addStyleName(String)public String getPrimaryStyleName()
ComponentComponent.setPrimaryStyleName(String) for a better description of
the primary stylename.getPrimaryStyleName in interface ComponentgetPrimaryStyleName in class AbstractComponentpublic void setPrimaryStyleName(String style)
ComponentThe primary style name identifies the component when applying the CSS theme to the Component. By changing the style name all CSS rules targeted for that style name will no longer apply, and might result in the component not working as intended.
To preserve the original style of the component when changing to a new primary style you should make your new primary style inherit the old primary style using the SASS @include directive. See more in the SASS tutorials.
setPrimaryStyleName in interface ComponentsetPrimaryStyleName in class AbstractComponentstyle - The new primary style namepublic void setEnabled(boolean enabled)
Component
Button enabled = new Button("Enabled");
enabled.setEnabled(true); // The default
layout.addComponent(enabled);
Button disabled = new Button("Disabled");
disabled.setEnabled(false);
layout.addComponent(disabled);
setEnabled in interface ComponentsetEnabled in class AbstractComponentenabled - a boolean value specifying if the component should be enabled
or notpublic boolean isEnabled()
ComponentAs a security feature, all updates for disabled components are blocked on the server-side.
Note that this method only returns the status of the component and does not take parents into account. Even though this method returns true the component can be disabled to the user if a parent is disabled.
isEnabled in interface ComponentisEnabled in class AbstractComponenttrue if the component and its parent are enabled,
false otherwise.VariableOwner.isEnabled()public float getWidth()
SizeablegetWidth in interface SizeablegetWidth in class AbstractComponentpublic float getHeight()
SizeablegetHeight in interface SizeablegetHeight in class AbstractComponentpublic Sizeable.Unit getWidthUnits()
SizeablegetWidthUnits in interface SizeablegetWidthUnits in class AbstractComponentpublic Sizeable.Unit getHeightUnits()
SizeablegetHeightUnits in interface SizeablegetHeightUnits in class AbstractComponentpublic void setHeight(String height)
SizeablesetHeight in interface SizeablesetHeight in class AbstractComponentheight - in CSS style string representationpublic void setWidth(float width,
Sizeable.Unit unit)
SizeablesetWidth in interface SizeablesetWidth in class AbstractComponentwidth - the width of the object.unit - the unit used for the width.public void setHeight(float height,
Sizeable.Unit unit)
SizeablesetHeight in interface SizeablesetHeight in class AbstractComponentheight - the height of the object.unit - the unit used for the width.public void setWidth(String width)
SizeablesetWidth in interface SizeablesetWidth in class AbstractComponentwidth - in CSS style string representation, null or empty string to
resetpublic void setSizeFull()
SizeablesetSizeFull in interface SizeablesetSizeFull in class AbstractComponentpublic void setSizeUndefined()
SizeablesetSizeUndefined in interface SizeablesetSizeUndefined in class AbstractComponentpublic void setWidthUndefined()
SizeablesetWidthUndefined in interface SizeablesetWidthUndefined in class AbstractComponentpublic void setHeightUndefined()
SizeablesetHeightUndefined in interface SizeablesetHeightUndefined in class AbstractComponentpublic void setId(String id)
ComponentsetId in interface ComponentsetId in class AbstractComponentid - An alphanumeric idpublic String getId()
ComponentgetId in interface ComponentgetId in class AbstractComponentpublic void setDebugId(String id)
setDebugId in class AbstractComponentpublic String getDebugId()
getDebugId in class AbstractComponentpublic String getCaption()
Component
See Component.setCaption(String) for a detailed description of the
caption.
getCaption in interface ComponentgetCaption in class AbstractComponentnull if the caption is
not set.Component.setCaption(String)public void setCaption(String caption)
Component
A caption is an explanatory textual label accompanying a user
interface component, usually shown above, left of, or inside the
component. Icon (see setIcon() is
closely related to caption and is usually displayed horizontally before
or after it, depending on the component and the containing layout.
The caption can usually also be given as the first parameter to a constructor, though some components do not support it.
RichTextArea area = new RichTextArea();
area.setCaption("You can edit stuff here");
area.setValue("<h1>Helpful Heading</h1>"
+ "<p>All this is for you to edit.</p>");
The contents of a caption are automatically quoted, so no raw HTML can be rendered in a caption. The validity of the used character encoding, usually UTF-8, is not checked.
The caption of a component is, by default, managed and displayed by the
layout component or component container in which the component is placed.
For example, the VerticalLayout component shows the captions
left-aligned above the contained components, while the FormLayout
component shows the captions on the left side of the vertically laid
components, with the captions and their associated components
left-aligned in their own columns. The CustomComponent does not
manage the caption of its composition root, so if the root component has
a caption, it will not be rendered. Some components, such as
Button and Panel, manage the caption themselves and
display it inside the component.
setCaption in interface ComponentsetCaption in class AbstractComponentcaption - the new caption for the component. If the caption is
null, no caption is shown and it does not normally
take any spacepublic void setCaptionAsHtml(boolean captionAsHtml)
AbstractComponentIf set to true, the captions are rendered in the browser as HTML and the developer is responsible for ensuring no harmful HTML is used. If set to false, the caption is rendered in the browser as plain text.
The default is false, i.e. to render that caption as plain text.
setCaptionAsHtml in class AbstractComponentcaptionAsHtml - true if the captions are rendered as HTML, false if rendered
as plain textpublic boolean isCaptionAsHtml()
AbstractComponentThe default is false, i.e. to render that caption as plain text.
isCaptionAsHtml in class AbstractComponentpublic Resource getIcon()
Component
See Component.setIcon(Resource) for a detailed description of the icon.
getIcon in interface ComponentgetIcon in class AbstractComponentnull if the
component has no iconComponent.setIcon(Resource)public void setIcon(Resource icon)
AbstractComponentsetIcon in interface ComponentsetIcon in class AbstractComponenticon - the icon to be shown with the component's caption.Component.getIcon(),
Component.setCaption(String)public String getDescription()
ComponentGets the components description, used in tooltips and can be displayed directly in certain other components such as forms. The description can be used to briefly describe the state of the component to the user. The description string may contain certain XML tags:
| Tag | Description | Example |
| <b> | bold | bold text |
| <i> | italic | italic text |
| <u> | underlined | underlined text |
| <br> | linebreak | N/A |
| <ul> <li>item1 <li>item1 </ul> |
item list |
|
These tags may be nested.
getDescription in interface ComponentgetDescription in class AbstractComponentStringpublic void setDescription(String description)
AbstractComponentAbstractComponent.getDescription() for more
information on what the description is.setDescription in class AbstractComponentdescription - the new description string for the component.AbstractComponent.setDescription(String, ContentMode)public void setDescription(String description, ContentMode mode)
AbstractComponentmode. See
AbstractComponent.getDescription() for more information on what the description
is.
If the content mode is ContentMode.HTML the
description is displayed as HTML in tooltips or directly in certain
components so care should be taken to avoid creating the possibility for
HTML injection and possibly XSS vulnerabilities.
setDescription in class AbstractComponentdescription - the new description string for the component.mode - the content mode for the descriptionpublic ErrorMessage getErrorMessage()
AbstractComponentgetErrorMessage in class AbstractComponentpublic ErrorMessage getComponentError()
AbstractComponentgetComponentError in class AbstractComponentpublic void setComponentError(ErrorMessage componentError)
AbstractComponentsetComponentError in class AbstractComponentcomponentError - the new ErrorMessage of the component.Copyright © 2022 Vaadin Ltd. All rights reserved.