Class Element<T extends Element<T>>
- Direct Known Subclasses:
Base,ContainerElement,Head,Link,Meta,Param,RawTextElement,Script,Source,Text,Track,VisualElement
The Element class provides the foundation for building dynamic, server-side HTML
elements with bidirectional communication between server and client. It manages the element
hierarchy, attributes, lifecycle, and event dispatching.
Features:
- Parent-child element relationships with automatic ID assignment
- Attribute management with automatic DOM synchronization
- Event dispatching for both client and server events
- Lifecycle management (initialization, creation, updates)
- Weak reference handling to prevent memory leaks
- Dynamic content updates with minimal DOM manipulation
- Drag and drop support
- JavaScript execution from server-side code
Usage:
public class MyElement extends Element {
public MyElement() {
super("div");
}
@Override
protected void initialize() {
// Setup element structure
addElement(new Text("Hello World"));
}
@Override
protected void create() {
// Configure element after initialization
addAttribute("class", "my-element");
}
}
- Since:
- 2007
- Version:
- 1.0
- Author:
- Marvin P. Warble Jr.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal ElementaddAttribute(String name) Adds a boolean HTML attribute (an attribute with no value).final ElementaddAttribute(String name, boolean flag) Adds or removes a boolean HTML attribute based on the flag value.final ElementaddAttribute(String name, String value) Adds an HTML attribute with the specified name and value.final ElementaddAttribute(String name, String value, boolean updateDom) Adds an HTML attribute with control over DOM synchronization.addElement(Element child) Adds a child element to this element.protected voidAdds a line break element.protected voidaddLineOfText(String text) Appends text content followed by a line break to this element.protected voidaddLineOfText(String text, CssStyle style) Appends text content with a CssStyle followed by a line break to this element.protected voidaddLineOfText(String text, String style) Appends text content with inline CSS styling followed by a line break to this element.protected voidAdds an empty paragraph element.protected voidaddParagraph(String text) Adds a paragraph element containing the specified text.protected voidaddSpacer(int height) Adds a vertical spacer element with the specified height in pixels.protected voidAppends a Text element to this element.voidAppends text content to this element.protected voidAppends text content with a CssStyle to this element.protected voidAppends text content with inline CSS styling to this element.final voidAssigns an auto-generated ID to this element from the page's ID sequence.booleancontainsElement(Element child) Checks if this element contains the specified child element.booleanChecks if this element contains a descendant with the specified ID.protected voidcreate()Hook method called during element creation.final voiddispatchEvent(ClientEvent event) Dispatches a client event to registered listeners.final voiddispatchEvent(ExtServerEvent event) Dispatches an extended server event to registered listeners.final voiddispatchEvent(PageEvent event) Dispatches a page event to the page's event dispatcher.final voiddispatchEvent(ServerEvent event) Dispatches a server event to registered listeners.booleanCompares this element to another object for equality.protected final voidExcludes the ID from being rendered in the HTML output.protected final voidExecutes a JavaScript statement on the client.protected final voidExecutes a JavaScript function on the client with the specified parameters.protected final voidExecutes a JavaScript function on the client with parameters from a list.protected StringReturns the accept attribute value.Returns all elements in this element's subtree.getAncestor(int generation) Returns an ancestor element at the specified generation distance.final StringgetAttribute(String name) Returns the value of the specified attribute.final AttributeMapReturns a copy of all attributes on this element.final StringReturns thedata-componentattribute value that identifies this element as a custom component.getDir()Returns the dir attribute value.getElement(int index) Returns the child element at the specified index.getElementById(String id) Finds a descendant element by its ID.intReturns the number of child elements.intgetElementCount(boolean recursive) Returns the number of child elements, optionally including all descendants.Returns the direct children of this element.getElements(boolean recursive) Returns the children of this element, optionally including all descendants.getElementsByComponentName(String componentName, boolean recursive) Returns all descendant elements that have the specifieddata-componentattribute value.getElementsByTagName(String tagName, boolean recursive) Finds all descendant elements with the specified tag name.getHtml()Returns the complete HTML of this element including its tags and children.voidgetHtml(StringBuilder sb) Appends this element's HTML to the provided StringBuilder.final StringgetId()Returns the unique identifier for this element.Returns the inner HTML content of this element (excluding the element's own tags).protected voidAppends the inner HTML of this element to the specified StringBuilder.protected StringgetIs()Returns the is attribute value.protected StringReturns the itemid attribute value.protected StringReturns the itemprop attribute value.protected StringReturns the itemref attribute value.protected StringReturns the itemtype attribute value.getLang()Returns the lang attribute value.Returns the next sibling element (the element immediately after this one in the parent's children).final HtmlPagegetPage()Returns the page this element is attached to.final ElementReturns the parent element.protected StringgetPart()Returns the part attribute value.Returns the previous sibling element (the element immediately before this one in the parent's children).protected StringgetSlot()Returns the slot attribute value.final StringReturns the HTML tag name for this element.Returns the text content of this element and all its descendants.protected StringConstructs a URL for the specified page class with optional parameters.final booleanhasAttribute(String name) Checks if this element has the specified attribute.booleanChecks if this element has any child elements.protected voidhidden()Called when this element has been hidden due to a parent's visibility change.protected voidHook method called during element initialization.protected TinsertElement(int index, Element child) Inserts a child element at the specified index.booleanChecks if this element is a direct child of the element with the specified ID.booleanChecks if this element uses a self-closing tag.final booleanChecks if this element has been created (completed the create lifecycle).booleanisDescendantOf(Element element) Checks if this element is a descendant of the specified element.booleanisDescendantOf(String id) Checks if this element is a descendant of the element with the specified ID.booleanChecks if this element has been initialized.protected booleanReturns whether the itemscope attribute is set.booleanReturns whether translate is enabled.voidonCallback(String callbackId) Callback method invoked when a client callback is received.protected voidHook method called after the element has been created.protected voidonElementAdded(Element child) Hook method called when a child element has been added.protected voidonElementRemoved(Element child) Hook method called when a child element has been removed.protected voidonHashChange(String hash) Hook method called when the URL hash fragment changes.protected voidonHidden()Hook method called when this element is hidden.protected voidHook method called after the element has been initialized.voidonJsReturn(String callbackId, String retval) Callback method invoked when a JavaScript function returns a value.protected voidHook method called when the page has finished loading.protected voidHook method called when the page is being unloaded.protected voidHook method called during refresh operations.protected voidHook method called when this element is removed from a page.protected voidonShown()Hook method called when this element is shown.protected voidHook method called after the element has been updated.voidonUserEvent(UserEvent event) Callback method invoked when a user event is received.protected voidprewrite()Hook method called before the element is written to output.final voidrecreate()Recreates this element by resetting and re-running the create lifecycle.voidrefresh()Refreshes this element and all its descendants.voidRefreshes this element and descendants, excluding the refresher element.protected voidRegisters this element for addition to the DOM.voidregisterListener(ClientEventListener listener, Class<? extends ClientEvent> eventType) Registers a listener for client events of the specified type.voidregisterListener(ClientEventListener listener, Class<? extends ClientEvent> eventType, Boolean value) Registers a listener for client events with a boolean value.voidregisterListener(ClientEventListener listener, Class<? extends ClientEvent> eventType, Number value) Registers a listener for client events with a numeric value.voidregisterListener(ClientEventListener listener, Class<? extends ClientEvent> eventType, String value) Registers a listener for client events with a string value.voidregisterListener(ExtServerEventListener listener, Class<? extends ExtServerEvent>... eventTypes) Registers a listener for one or more extended server event types.voidregisterListener(PageEventListener listener, Class<? extends PageEvent>... eventTypes) Registers a listener for page-level events.voidregisterListener(ServerEventListener listener, Class<? extends ServerEvent>... eventTypes) Registers a listener for one or more server event types.protected voidRegisters this element for removal from the DOM.voidRegisters this element for update in the DOM.protected voidRemoves all child elements from this element.final voidremoveAttribute(String name) Removes an HTML attribute from this element.final voidremoveAttribute(String name, boolean updateDom) Removes an HTML attribute with control over DOM synchronization.protected voidremoveElement(Element child) Removes a child element from this element.protected voidremoveElement(String id) Removes a child element by its ID.final voidRemoves this element from its parent.voidRequests a callback from the client.voidrequestCallback(long delay) Requests a delayed callback from the client.voidRequests a callback from the client with a specific identifier.voidrequestCallback(String id, long delay) Requests a delayed callback from the client with a specific identifier.final voidResets the element's ID if it matches the specified parent ID prefix.final voidscrollTo(int pos) Scrolls this element to the specified position.final voidScrolls this element to the bottom.final voidScrolls this element to the top.protected final Tself()protected voidsendCommand(Command command) Sends a command to the client.voidSends pending updates to the client.protected TSets the accept attribute.final voidsetComponent(String componentName) Sets thedata-componentattribute to identify this element as a custom component in the DOM.setDir(TextDirection direction) Sets the text direction for the element using aTextDirectionenum value.Sets the dir attribute for text directionality.protected TsetElement(Element child) Replaces all child elements with a single child element.final TSets the unique identifier for this element.protected TSets the is attribute for custom element identification.protected TSets the itemid attribute for microdata.protected TsetItemProp(String itemProp) Sets the itemprop attribute for microdata.protected TsetItemRef(String itemRef) Sets the itemref attribute for microdata.protected TsetItemScope(boolean itemScope) Sets the itemscope boolean attribute for microdata.protected TsetItemType(String itemType) Sets the itemtype attribute for microdata.Sets the lang attribute for the element's language.voidsetOnError(String value) Sets the JavaScriptonerrorevent handler for this element.voidSets the JavaScriptonloadevent handler for this element.final voidAssociates this element and all its descendants with the specified page.final voidSets the parent element for this element.protected TSets the part attribute for CSS shadow parts.protected TSets the slot attribute for shadow DOM slot assignment.protected final voidsetTagName(String tagName) Sets the HTML tag name for this element.voidSets the text content of this element, replacing any existing content.protected voidSets the text content of this element with a CssStyle, replacing any existing content.protected voidSets the text content of this element with a font, replacing any existing content.protected voidSets the text content of this element with inline CSS styling, replacing any existing content.setTranslate(boolean translate) Sets the translate attribute.protected voidshown()Called when this element has become visible due to a parent's visibility change.toString()Returns a string representation of this element.voidunregisterListener(EventListener listener) Unregisters a listener from this element's event dispatcher.final voidupdate()Triggers a DOM update for this element.final voidTriggers an attribute update for this element.
-
Constructor Details
-
Element
public Element()Constructs a new Element with default initialization.Initializes the children collection, attributes map, and event dispatcher.
-
Element
Constructs a new Element with the specified HTML tag name.Creates a closed tag element (requires closing tag like
</div>).- Parameters:
tagName- The HTML tag name (e.g., "div", "span", "table").
-
Element
Constructs a new Element with the specified HTML tag name and tag type.- Parameters:
tagName- The HTML tag name (e.g., "div", "span", "br").closed-truefor closed tags (requires closing tag),falsefor self-closing tags.
-
-
Method Details
-
setId
Sets the unique identifier for this element.The ID is also added as an HTML attribute for client-side identification.
- Parameters:
id- The unique identifier for this element.- Returns:
- This element for method chaining.
-
setComponent
Sets thedata-componentattribute to identify this element as a custom component in the DOM.The
data-componentattribute provides a semantic way to mark elements that represent custom components, independent of their HTML tag name or CSS classes. This is useful for:- Identifying custom component instances within a complex element tree
- Locating components programmatically via
getElementsByComponentName(String, boolean) - Client-side JavaScript component initialization and binding
- Distinguishing between multiple instances of the same element type serving different roles
Usage:
// Mark a div as a custom "user-card" component Div card = new Div(); card.setComponent("user-card"); // Later, find all user-card components in a container Elements cards = container.getElementsByComponentName("user-card", true);- Parameters:
componentName- the component name to assign; should be a descriptive, lowercase, hyphen-separated identifier (e.g., "date-picker", "user-card")
-
setParent
Sets the parent element for this element.The parent is stored as a weak reference to prevent memory leaks.
- Parameters:
parent- The parent element.
-
setPage
Associates this element and all its descendants with the specified page.This method assigns an ID to this element if needed and propagates the page reference to all child elements. If page is null, it triggers the
onRemovedFromPage()callback.- Parameters:
page- The page to associate with, or null to disassociate.
-
setDir
Sets the dir attribute for text directionality.Specifies the text direction (ltr, rtl, auto).
- Parameters:
dir- The text direction value.- Returns:
- This element for method chaining.
-
setDir
Sets the text direction for the element using aTextDirectionenum value.- Parameters:
direction- The text direction (LTR or RTL).- Returns:
- This element for method chaining.
-
setLang
Sets the lang attribute for the element's language.Specifies the language of the element's content.
- Parameters:
lang- The BCP 47 language tag.- Returns:
- This element for method chaining.
-
setTranslate
Sets the translate attribute.Specifies whether the element's content should be translated when the page is localized.
- Parameters:
translate- True to enable translation, false to disable.- Returns:
- This element for method chaining.
-
setOnLoad
Sets the JavaScriptonloadevent handler for this element.Fires when the element and its dependent resources have finished loading. Applicable to elements such as
<script>,<link>,<style>,<img>,<iframe>,<body>,<object>, and<embed>.- Parameters:
value- The JavaScript code to execute on load.
-
setOnError
Sets the JavaScriptonerrorevent handler for this element.Fires when the element fails to load its dependent resource. Applicable to elements such as
<script>,<link>,<style>,<img>,<audio>,<video>, and<object>.- Parameters:
value- The JavaScript code to execute on error.
-
addElement
Adds a child element to this element.The child is removed from its previous parent if it has one, then added to this element's children. If this element is already attached to a page, the child is also attached and registered for DOM addition.
- Parameters:
child- The child element to add.- Returns:
- this element for method chaining
-
addText
Appends text content to this element.- Parameters:
text- The text content to append.
-
setText
Sets the text content of this element, replacing any existing content.- Parameters:
text- The text content to set.
-
getDir
Returns the dir attribute value.- Returns:
- The text direction, or
nullif not set.
-
getLang
Returns the lang attribute value.- Returns:
- The language tag, or
nullif not set.
-
isTranslate
public boolean isTranslate()Returns whether translate is enabled.- Returns:
trueif translation is enabled,falseotherwise.
-
isInitialized
public boolean isInitialized()Checks if this element has been initialized.- Returns:
trueifinitialize()has been called,falseotherwise.
-
getParent
Returns the parent element.- Returns:
- The parent element, or
nullif this element has no parent.
-
getPage
Returns the page this element is attached to.- Returns:
- The HtmlPage, or
nullif not attached to a page.
-
getTagName
Returns the HTML tag name for this element.- Returns:
- The tag name (e.g., "div", "span", "table").
-
getId
Returns the unique identifier for this element.- Returns:
- The element's ID, or
nullif not set.
-
getComponent
Returns thedata-componentattribute value that identifies this element as a custom component.Returns the component name previously set via
setComponent(String), ornullif no component name has been assigned to this element.- Returns:
- the component name, or
nullif thedata-componentattribute is not set - See Also:
-
hasAttribute
Checks if this element has the specified attribute.- Parameters:
name- The attribute name to check.- Returns:
trueif the attribute exists,falseotherwise.
-
getAttribute
Returns the value of the specified attribute.- Parameters:
name- The attribute name.- Returns:
- The attribute value, or
nullif not found.
-
getAttributes
Returns a copy of all attributes on this element.- Returns:
- A copy of the attribute map.
-
isCreated
public final boolean isCreated()Checks if this element has been created (completed the create lifecycle).- Returns:
trueifcreate()has been called,falseotherwise.
-
getInnerHtml
Returns the inner HTML content of this element (excluding the element's own tags).- Returns:
- The HTML content of all child elements.
-
getHtml
Returns the complete HTML of this element including its tags and children.- Returns:
- The complete HTML representation.
- Throws:
ElementException- If an error occurs during HTML generation.
-
getAncestor
Returns an ancestor element at the specified generation distance.A generation of 1 returns the parent, 2 returns the grandparent, etc.
- Parameters:
generation- The number of generations up the hierarchy.- Returns:
- The ancestor element, or
nullif not found.
-
getTextContent
Returns the text content of this element and all its descendants.HTML tags, script content, style content, and HTML comments are removed. Special HTML entities are replaced with spaces.
- Returns:
- The plain text content.
-
hasElements
public boolean hasElements()Checks if this element has any child elements.- Returns:
trueif this element has children,falseotherwise.
-
getElement
Returns the child element at the specified index.- Parameters:
index- The zero-based index of the child.- Returns:
- The child element, or
nullif index is out of bounds.
-
getElements
Returns the direct children of this element.- Returns:
- A copy of the children collection.
-
getElements
Returns the children of this element, optionally including all descendants.- Parameters:
recursive- Iftrue, returns all elements at every level; iffalse, returns only direct children.- Returns:
- A collection of elements.
-
getAllElements
Returns all elements in this element's subtree.- Returns:
- A collection of all elements at every level.
-
getElementCount
public int getElementCount()Returns the number of child elements.- Returns:
- The count of direct child elements.
-
getElementCount
public int getElementCount(boolean recursive) Returns the number of child elements, optionally including all descendants.- Parameters:
recursive- Iftrue, counts all descendants; iffalse, counts only direct children.- Returns:
- The element count.
-
getNextSibling
Returns the next sibling element (the element immediately after this one in the parent's children).- Returns:
- The next sibling, or
nullif this is the last child or has no parent.
-
getPrevSibling
Returns the previous sibling element (the element immediately before this one in the parent's children).- Returns:
- The previous sibling, or
nullif this is the first child or has no parent.
-
containsElement
Checks if this element contains the specified child element.- Parameters:
child- The element to check for.- Returns:
- true if the child is a direct child of this element, false otherwise.
-
containsElement
Checks if this element contains a descendant with the specified ID.- Parameters:
id- The ID to search for.- Returns:
trueif a descendant with the ID exists,falseotherwise.
-
getElementById
Finds a descendant element by its ID.Searches this element's children and all descendants recursively.
- Parameters:
id- The ID to search for.- Returns:
- The element with the matching ID, or
nullif not found.
-
getElementsByTagName
Finds all descendant elements with the specified tag name.- Parameters:
tagName- The HTML tag name to search for.recursive- Iftrue, searches all descendants; iffalse, only direct children.- Returns:
- A collection of matching elements.
-
getElementsByComponentName
Returns all descendant elements that have the specifieddata-componentattribute value.Searches the children of this element for elements whose
data-componentattribute matches the given component name. This provides a way to locate custom component instances within the element tree, similar to howgetElementsByTagName(String, boolean)locates elements by HTML tag name.Usage:
// Find all "chart-widget" components in the page body Elements charts = body.getElementsByComponentName("chart-widget", true); // Find only direct child components (non-recursive) Elements topLevel = container.getElementsByComponentName("nav-item", false);- Parameters:
componentName- the component name to search for, as set bysetComponent(String)recursive- iftrue, searches the entire subtree; iffalse, searches only direct children- Returns:
- an
Elementscollection of matching elements; nevernullbut may be empty - See Also:
-
isChildOf
Checks if this element is a direct child of the element with the specified ID.- Parameters:
id- The ID of the potential parent.- Returns:
trueif this element's parent has the specified ID,falseotherwise.
-
isDescendantOf
Checks if this element is a descendant of the specified element.- Parameters:
element- The potential ancestor element.- Returns:
trueif this element is a descendant,falseotherwise.
-
isDescendantOf
Checks if this element is a descendant of the element with the specified ID.- Parameters:
id- The ID of the potential ancestor.- Returns:
trueif this element is a descendant,falseotherwise.
-
resetId
Resets the element's ID if it matches the specified parent ID prefix.This method is used during element re-parenting to reset hierarchical IDs.
- Parameters:
parentId- The parent ID to check against.
-
assignId
Assigns an auto-generated ID to this element from the page's ID sequence.If the element doesn't already have an ID and IDs are not excluded, a new unique ID is generated in the format "ai-{sequence}".
- Parameters:
page- The page to get the next ID from.
-
removeFromParent
public final void removeFromParent()Removes this element from its parent.If this element has a parent, it is removed from the parent's children collection.
-
addAttribute
Adds an HTML attribute with the specified name and value.If the value is null, the attribute is removed instead.
- Parameters:
name- The attribute name.value- The attribute value.- Returns:
- This element for method chaining.
-
addAttribute
Adds an HTML attribute with control over DOM synchronization.If the value is null, the attribute is removed instead.
- Parameters:
name- The attribute name.value- The attribute value.updateDom- If true, triggers a DOM update on the client.- Returns:
- This element for method chaining.
-
addAttribute
Adds a boolean HTML attribute (an attribute with no value).Boolean attributes like "disabled", "readonly", or "checked" are present or absent rather than having a value.
- Parameters:
name- The attribute name.- Returns:
- This element for method chaining.
-
addAttribute
Adds or removes a boolean HTML attribute based on the flag value.If flag is true, the attribute is added. If false, it is removed.
- Parameters:
name- The attribute name.flag- If true, adds the attribute; if false, removes it.- Returns:
- This element for method chaining.
-
removeAttribute
Removes an HTML attribute from this element.- Parameters:
name- The attribute name to remove.
-
removeAttribute
Removes an HTML attribute with control over DOM synchronization.- Parameters:
name- The attribute name to remove.updateDom- If true, triggers a DOM update on the client.
-
registerListener
Registers a listener for client events of the specified type.The element's attributes are updated to trigger event generation on the client side.
- Parameters:
listener- The listener to receive events.eventType- The class of client event to listen for.
-
registerListener
public void registerListener(ClientEventListener listener, Class<? extends ClientEvent> eventType, Number value) Registers a listener for client events with a numeric value.- Parameters:
listener- The listener to receive events.eventType- The class of client event to listen for.value- A numeric value associated with the event registration.
-
registerListener
public void registerListener(ClientEventListener listener, Class<? extends ClientEvent> eventType, Boolean value) Registers a listener for client events with a boolean value.- Parameters:
listener- The listener to receive events.eventType- The class of client event to listen for.value- A boolean value associated with the event registration.
-
registerListener
public void registerListener(ClientEventListener listener, Class<? extends ClientEvent> eventType, String value) Registers a listener for client events with a string value.This is the core registration method that updates client event attributes and registers the listener with the event dispatcher.
- Parameters:
listener- The listener to receive events.eventType- The class of client event to listen for.value- A string value associated with the event registration.
-
registerListener
public void registerListener(ServerEventListener listener, Class<? extends ServerEvent>... eventTypes) Registers a listener for one or more server event types.- Parameters:
listener- The listener to receive events.eventTypes- The classes of server events to listen for.
-
registerListener
public void registerListener(ExtServerEventListener listener, Class<? extends ExtServerEvent>... eventTypes) Registers a listener for one or more extended server event types.- Parameters:
listener- The listener to receive events.eventTypes- The classes of extended server events to listen for.
-
registerListener
Registers a listener for page-level events.The listener is registered with the page rather than the element.
- Parameters:
listener- The listener to receive page events.eventTypes- The classes of page events to listen for.
-
unregisterListener
Unregisters a listener from this element's event dispatcher.- Parameters:
listener- The listener to unregister.
-
dispatchEvent
Dispatches a server event to registered listeners.The event is dispatched to listeners registered on this element. If the event bubbles, it is also dispatched to parent elements.
- Parameters:
event- The server event to dispatch.
-
dispatchEvent
Dispatches an extended server event to registered listeners.The event is dispatched to listeners registered on this element. If the event bubbles, it is also dispatched to parent elements.
- Parameters:
event- The extended server event to dispatch.
-
dispatchEvent
Dispatches a client event to registered listeners.The event is dispatched to listeners registered on this element. If the event bubbles, it is also dispatched to parent elements.
- Parameters:
event- The client event to dispatch.
-
dispatchEvent
Dispatches a page event to the page's event dispatcher.- Parameters:
event- The page event to dispatch.
-
update
public final void update()Triggers a DOM update for this element.The element is registered for update with the page, causing its HTML to be re-rendered and sent to the client.
-
updateAttributes
public final void updateAttributes()Triggers an attribute update for this element.If the element has been created, only the attributes are updated on the client. Otherwise, a full element update is triggered.
-
scrollTo
public final void scrollTo(int pos) Scrolls this element to the specified position.- Parameters:
pos- The scroll position in pixels.
-
scrollToTop
public final void scrollToTop()Scrolls this element to the top. -
scrollToBottom
public final void scrollToBottom()Scrolls this element to the bottom. -
recreate
public final void recreate()Recreates this element by resetting and re-running the create lifecycle.This triggers a full DOM update for this element.
-
refresh
public void refresh()Refreshes this element and all its descendants.Calls
onRefresh()on this element and recursively on all children. -
refresh
Refreshes this element and descendants, excluding the refresher element.Useful when an element triggers a refresh but should not be refreshed itself.
- Parameters:
refresher- The element that initiated the refresh (will be excluded).
-
getHtml
Appends this element's HTML to the provided StringBuilder.- Parameters:
sb- The StringBuilder to append to.
-
sendUpdate
public void sendUpdate()Sends pending updates to the client.If this element has been created and is attached to a page, triggers the page to send all pending DOM updates to the client.
-
requestCallback
public void requestCallback()Requests a callback from the client.Sends a command to the browser to trigger a callback to this element's
onCallback(String)method with an empty identifier. -
requestCallback
public void requestCallback(long delay) Requests a delayed callback from the client.Sends a command to the browser to trigger a callback to this element's
onCallback(String)method after the specified delay.- Parameters:
delay- The delay in milliseconds before the callback is triggered.
-
requestCallback
Requests a callback from the client with a specific identifier.Sends a command to the browser to trigger a callback to this element's
onCallback(String)method with the specified identifier.- Parameters:
id- The callback identifier to pass toonCallback(String).
-
requestCallback
Requests a delayed callback from the client with a specific identifier.Sends a command to the browser to trigger a callback to this element's
onCallback(String)method with the specified identifier after the specified delay.- Parameters:
id- The callback identifier to pass toonCallback(String).delay- The delay in milliseconds before the callback is triggered.
-
isClosedTag
public boolean isClosedTag()Checks if this element uses a self-closing tag.- Returns:
trueif the tag is self-closing (e.g.,<br/>),falseotherwise.
-
equals
Compares this element to another object for equality.Two elements are equal if they have the same ID.
-
toString
Returns a string representation of this element. -
onCallback
Callback method invoked when a client callback is received.Override this method to handle callbacks requested via
requestCallback(String).- Parameters:
callbackId- The callback identifier.
-
onJsReturn
Callback method invoked when a JavaScript function returns a value.Override this method to handle return values from JavaScript executions.
- Parameters:
callbackId- The callback identifier.retval- The return value from JavaScript.
-
onUserEvent
Callback method invoked when a user event is received.Override this method to handle custom user events.
- Parameters:
event- The user event.
-
setTagName
Sets the HTML tag name for this element.- Parameters:
tagName- The HTML tag name (e.g., "div", "span", "table").
-
setIs
Sets the is attribute for custom element identification.Specifies that a standard HTML element should behave like a registered custom built-in element.
- Parameters:
is- The custom element name.- Returns:
- This element for method chaining.
-
setItemId
Sets the itemid attribute for microdata.The global identifier for a microdata item.
- Parameters:
itemId- The item identifier URL.- Returns:
- This element for method chaining.
-
setItemProp
Sets the itemprop attribute for microdata.Adds a property name to a microdata item.
- Parameters:
itemProp- The property name.- Returns:
- This element for method chaining.
-
setItemRef
Sets the itemref attribute for microdata.References other elements that are not descendants of the element with the itemscope attribute.
- Parameters:
itemRef- Space-separated list of element IDs.- Returns:
- This element for method chaining.
-
setItemScope
Sets the itemscope boolean attribute for microdata.Creates a new item scope for microdata.
- Parameters:
itemScope- True to add itemscope, false to remove.- Returns:
- This element for method chaining.
-
setItemType
Sets the itemtype attribute for microdata.Specifies the URL of the vocabulary used to define item properties.
- Parameters:
itemType- The item type URL.- Returns:
- This element for method chaining.
-
setPart
Sets the part attribute for CSS shadow parts.Contains space-separated part names of the element for styling with ::part().
- Parameters:
part- The part name(s).- Returns:
- This element for method chaining.
-
setSlot
Sets the slot attribute for shadow DOM slot assignment.Assigns a slot in a shadow DOM shadow tree to an element.
- Parameters:
slot- The slot name.- Returns:
- This element for method chaining.
-
setAccept
Sets the accept attribute.Specifies a comma-separated list of content types that the server accepts. Used on
<input>elements withtype="file"to filter file selection, and on<form>elements to specify accepted MIME types.- Parameters:
accept- Comma-separated list of accepted content types.- Returns:
- This element for method chaining.
-
getIs
Returns the is attribute value.- Returns:
- The custom element name, or
nullif not set.
-
getItemId
Returns the itemid attribute value.- Returns:
- The item identifier, or
nullif not set.
-
getItemProp
Returns the itemprop attribute value.- Returns:
- The item property name, or
nullif not set.
-
getItemRef
Returns the itemref attribute value.- Returns:
- The item references, or
nullif not set.
-
isItemScope
protected boolean isItemScope()Returns whether the itemscope attribute is set.- Returns:
trueif itemscope is present,falseotherwise.
-
getItemType
Returns the itemtype attribute value.- Returns:
- The item type URL, or
nullif not set.
-
getPart
Returns the part attribute value.- Returns:
- The part name(s), or
nullif not set.
-
getSlot
Returns the slot attribute value.- Returns:
- The slot name, or
nullif not set.
-
getAccept
Returns the accept attribute value.The accept attribute specifies which file types are accepted by an
<input type="file">element. The value is a comma-separated list of file extensions (.jpg), MIME types (image/png), or special tokens likeaudio/*,video/*,image/*.- Returns:
- The accept value, or
nullif not set.
-
getUrl
Constructs a URL for the specified page class with optional parameters.Delegates to
HttpFile.getUrl(Class, Object...)to build the URL.- Parameters:
pageClass- The page class to generate a URL for.urlParams- The URL parameters to include.- Returns:
- The constructed URL string.
-
excludeId
protected final void excludeId()Excludes the ID from being rendered in the HTML output.When called, the element's ID will not appear in the generated HTML.
-
self
-
sendCommand
Sends a command to the client.- Parameters:
command- The command to send.
-
getInnerHtml
Appends the inner HTML of this element to the specified StringBuilder.Iterates through all child elements and appends their HTML representations to the builder. Uses a synchronized copy of the children list to avoid concurrent modification issues.
- Parameters:
sb- The StringBuilder to append the inner HTML to.
-
executeJs
Executes a JavaScript statement on the client.Sends a JavaScript command to the browser to execute the specified statement. The command is associated with this element's ID.
- Parameters:
statement- The JavaScript statement to execute.
-
executeJs
Executes a JavaScript function on the client with the specified parameters.Sends a JavaScript command to the browser to call the specified function with the provided parameters. Parameters are serialized to JSON for transmission.
- Parameters:
function- The JavaScript function to call.parameters- The parameters to pass to the function.
-
executeJs
Executes a JavaScript function on the client with parameters from a list.Sends a JavaScript command to the browser to call the specified function with parameters from the provided list. Parameters are serialized to JSON for transmission.
- Parameters:
function- The JavaScript function to call.parameters- The list of parameters to pass to the function.
-
setElement
Replaces all child elements with a single child element.All existing children are removed before adding the new child.
- Parameters:
child- The child element to set as the only child.- Returns:
- This element for method chaining.
-
insertElement
Inserts a child element at the specified index.The child is removed from its previous parent if it has one, then inserted at the specified index in this element's children.
- Parameters:
index- The index at which to insert the child.child- The child element to insert.- Returns:
- this element for method chaining
-
removeElement
Removes a child element from this element.The child is unlinked from this parent and registered for DOM removal if the element is attached to a page.
- Parameters:
child- The child element to remove.
-
removeElement
Removes a child element by its ID.- Parameters:
id- The ID of the child element to remove.
-
removeAllElements
protected void removeAllElements()Removes all child elements from this element.Each child is unlinked and registered for DOM removal if the element is attached to a page.
-
setText
Sets the text content of this element with inline CSS styling, replacing any existing content.- Parameters:
text- The text content to set.style- The inline CSS style string to apply to the text.
-
setText
Sets the text content of this element with a font, replacing any existing content.- Parameters:
text- The text content to set.font- The font to apply to the text.
-
setText
Sets the text content of this element with a CssStyle, replacing any existing content.- Parameters:
text- The text content to set.style- The CssStyle to apply to the text.
-
addText
Appends text content with inline CSS styling to this element.- Parameters:
text- The text content to append.style- The inline CSS style string to apply to the text.
-
addText
Appends text content with a CssStyle to this element.- Parameters:
text- The text content to append.style- The CssStyle to apply to the text.
-
addText
Appends a Text element to this element.- Parameters:
text- The Text element to append.
-
addLineOfText
Appends text content followed by a line break to this element.- Parameters:
text- The text content to append.
-
addLineOfText
Appends text content with inline CSS styling followed by a line break to this element.- Parameters:
text- The text content to append.style- The inline CSS style string to apply to the text.
-
addLineOfText
Appends text content with a CssStyle followed by a line break to this element.- Parameters:
text- The text content to append.style- The CssStyle to apply to the text.
-
addLineBreak
protected void addLineBreak()Adds a line break element. -
addSpacer
protected void addSpacer(int height) Adds a vertical spacer element with the specified height in pixels.- Parameters:
height- The height of the spacer in pixels.
-
addParagraph
protected void addParagraph()Adds an empty paragraph element. -
addParagraph
Adds a paragraph element containing the specified text.- Parameters:
text- the text content for the paragraph
-
initialize
protected void initialize()Hook method called during element initialization.Override this method to set up the element's structure by adding child elements. This is called before
create()and only once during the element's lifecycle. -
create
protected void create()Hook method called during element creation.Override this method to configure the element after initialization. This is called after
initialize()and only once during the element's lifecycle. -
prewrite
protected void prewrite()Hook method called before the element is written to output.Override this method to perform any last-minute configuration before rendering.
-
onInitialized
protected void onInitialized()Hook method called after the element has been initialized.Override this method to perform actions after initialization is complete.
-
onCreated
protected void onCreated()Hook method called after the element has been created.Override this method to perform actions after creation is complete.
-
onUpdated
protected void onUpdated()Hook method called after the element has been updated.Override this method to perform actions after a DOM update.
-
onPageLoaded
protected void onPageLoaded()Hook method called when the page has finished loading.Override this method to perform actions after the page is fully loaded in the browser.
-
onPageUnloaded
protected void onPageUnloaded()Hook method called when the page is being unloaded.Override this method to perform cleanup actions when the user navigates away.
-
onElementAdded
Hook method called when a child element has been added.- Parameters:
child- The child element that was added.
-
onElementRemoved
Hook method called when a child element has been removed.- Parameters:
child- The child element that was removed.
-
onRemovedFromPage
protected void onRemovedFromPage()Hook method called when this element is removed from a page.Override this method to perform cleanup when the element is detached.
-
onRefresh
protected void onRefresh()Hook method called during refresh operations.Override this method to update the element's state during a refresh.
-
onHashChange
Hook method called when the URL hash fragment changes.Override this method to respond to hash-based navigation changes within the page.
- Parameters:
hash- The new hash fragment value.
-
shown
protected void shown()Called when this element has become visible due to a parent's visibility change.StyledElementoverrides this asfinalto check CSS visibility, callonShown(), and cascade to child elements. -
onShown
protected void onShown()Hook method called when this element is shown.Override this method to respond to the element becoming visible.
-
onHidden
protected void onHidden()Hook method called when this element is hidden.Override this method to respond to the element being hidden.
-
registerAddition
protected void registerAddition()Registers this element for addition to the DOM. -
registerSubtraction
protected void registerSubtraction()Registers this element for removal from the DOM.Notifies the page that this element should be removed from the client-side DOM during the next update cycle.
-
registerUpdate
public void registerUpdate()Registers this element for update in the DOM.Notifies the page that this element has been modified and should be synchronized with the client-side DOM during the next update cycle.
-