- All Implemented Interfaces:
-
DomAttributes
,Cloneable
DomContainer
, which means it has a list of DomContent
children. In addition, element has attributes, attached listeners, and some special properties like tagname()
, id()
, and key()
.
DomElement
cannot be directly instantiated by calling constructor DomElement(String)
. Application code can instantiate elements more intuitively using Html
class. Attributes can be set by calling specialized fluent setters inherited from DomAttributes
.
Every element can have an id()
. Element ID is serialized as an id
attribute in HTML. Element ID has a special meaning in PushMode. Listeners require the element to have an ID. Listeners on ID-less elements are ignored. ID is also the default value of key()
.
Every element can have a key()
. It is the same as id()
by default, but it can be set separately via key(String)
. While id()
is sent to the browser and it should be unique in the document, key()
is used only server-side and it only needs to be unique among sibling elements. It is used in hierarchical DOM diff to pair corresponding elements in cases where some DOM nodes have been inserted or removed from parent's child list. If neither key()
nor id()
is specified, DOM diff uses element position to pair elements in compared DOM trees, which might result in unnecessarily big diffs if an element is inserted at the beginning of a long list. Absence of key()
thus doesn't impact functionality, only performance. And even then it matters only if siblings are inserted or removed.
In order to provide interactivity for elements, application can call onX()
methods to add event handlers or call binding overrides for two-way attributes like e.g. value
attribute on <input> element.
DomElement is not thread-safe. Concurrent writes will corrupt internal state. It is however safe for multiple threads to read the same DomElement as far as there are no concurrent writers. Application can freeze()
DOM subtree to prevent its accidental modification. This is particularly useful for DOM trees in caches that are likely to be read by multiple threads.
-
Constructor Summary
ConstructorDescriptionDomElement
(DomElement other) Creates deep unfrozen copy of another element.DomElement
(String tagname) -
Method Summary
Modifier and TypeMethodDescriptionadd
(DomContent child) Adds new child node to this element.Adds literal text to this element The text is first wrapped inDomText
.<C extends DomContent>
DomElementadd
(Collection<C> children) Adds all nodes in aCollection
to this element.<C extends DomContent>
DomElementAdds all nodes in aStream
to this element.assign
(DomElement other) boolean
attributeAsBoolean
(String name) attributeAsDouble
(String name) attributeAsInt
(String name) attributeAsString
(String name) Sets up two-way binding on attributechecked
.Sets up two-way binding on attributechecked
.clone()
Creates deep unfrozen clone of this element.boolean
Compares two elements.freeze()
Protects this element from further modification.static DomElement
static DomElement
int
hashCode()
Computes deep hash code of the element.id()
Gets element ID.Sets element's ID.key()
Gets element's pairing key.Sets element's pairing key.Adds event handler forchange
event.Adds event handler forclick
event.Adds event handler forinput
event.String[]
void
rawAttributes
(String[] attributes) void
rawListeners
(DomListener[] listeners) set
(DomAttribute attribute) set
(Iterable<DomAttribute> attributes) set
(Stream<DomAttribute> attributes) subscribe
(DomListener listener) tagname()
toPoster()
Sets up two-way binding on attributevalue
.Methods inherited from class com.machinezoo.pushmode.dom.DomContainer
children, descendants, element, elements, elements, rawChildCount, rawChildren, rawChildren, rawFreeze, text
Methods inherited from class com.machinezoo.pushmode.dom.DomContent
toString
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.machinezoo.pushmode.dom.DomAttributes
accept, accept, acceptCharset, acceptCharset, accesskey, accesskey, accumulate, accumulate, action, action, additive, additive, alignmentBaseline, alignmentBaseline, allowfullscreen, allowfullscreen, alt, alt, amplitude, amplitude, amplitude, amplitudeAsDouble, async, async, asyncAsBoolean, attributeName, attributeName, attributeType, attributeType, autocapitalize, autocapitalize, autocomplete, autocomplete, autofocus, autofocus, autofocusAsBoolean, autoplay, autoplay, autoplayAsBoolean, azimuth, azimuth, azimuth, azimuthAsDouble, baseFrequency, baseFrequency, baseFrequency, baseFrequencyAsDouble, baselineShift, baselineShift, baselineShift, baselineShiftAsDouble, begin, begin, bias, bias, bias, biasAsDouble, calcMode, calcMode, charset, charset, checked, checked, checkedAsBoolean, cite, cite, clazz, clazz, clazz, clipPath, clipPath, clipPathUnits, clipPathUnits, clipRule, clipRule, color, color, colorInterpolation, colorInterpolation, colorInterpolationFilters, colorInterpolationFilters, colorProfile, colorProfile, colorRendering, colorRendering, cols, cols, cols, colsAsInt, colspan, colspan, colspan, colspanAsInt, content, content, contenteditable, contenteditable, contextmenu, contextmenu, controls, controls, controlsAsBoolean, coords, coords, crossorigin, crossorigin, cursor, cursor, cx, cx, cx, cxAsDouble, cy, cy, cy, cyAsDouble, d, d, data, data, datetime, datetime, defaults, defaults, defaultsAsBoolean, defer, defer, deferAsBoolean, diffuseConstant, diffuseConstant, diffuseConstant, diffuseConstantAsDouble, dir, dir, direction, direction, disabled, disabled, disabledAsBoolean, display, display, divisor, divisor, divisor, divisorAsDouble, dominantBaseline, dominantBaseline, download, download, downloadAsBoolean, draggable, draggable, dropzone, dropzone, dur, dur, dx, dx, dx, dxAsDouble, dy, dy, dy, dyAsDouble, edgeMode, edgeMode, elevation, elevation, elevation, elevationAsDouble, enctype, enctype, end, end, externalResourcesRequired, externalResourcesRequired, fill, fill, fillOpacity, fillOpacity, fillOpacity, fillOpacityAsDouble, fillRule, fillRule, filter, filter, filterUnits, filterUnits, floodColor, floodColor, floodOpacity, floodOpacity, floodOpacity, floodOpacityAsDouble, fontFamily, fontFamily, fontSize, fontSize, fontSizeAdjust, fontSizeAdjust, fontSizeAdjust, fontSizeAdjustAsDouble, fontStretch, fontStretch, fontVariant, fontVariant, fontWeight, fontWeight, fontWeight, fontWeightAsInt, forid, forid, form, form, formaction, formaction, formmethod, formmethod, formnovalidate, formnovalidate, formnovalidateAsBoolean, formtarget, formtarget, fr, fr, fr, frAsDouble, from, from, fx, fx, fx, fxAsDouble, fy, fy, fy, fyAsDouble, gradientTransform, gradientTransform, gradientUnits, gradientUnits, headers, headers, height, height, height, height, heightAsDouble, heightAsInt, hidden, hidden, hiddenAsBoolean, high, high, high, highAsDouble, href, href, hreflang, hreflang, httpEquiv, httpEquiv, icon, icon, imageRendering, imageRendering, in, in, in2, in2, inputmode, inputmode, integrity, integrity, ismap, ismap, ismapAsBoolean, k1, k1, k1, k1AsDouble, k2, k2, k2, k2AsDouble, k3, k3, k3, k3AsDouble, k4, k4, k4, k4AsDouble, kernelMatrix, kernelMatrix, kernelUnitLength, kernelUnitLength, kernelUnitLength, kernelUnitLengthAsDouble, kerning, kerning, kerning, kerningAsDouble, keySplines, keySplines, keyTimes, keyTimes, kind, kind, label, label, lang, lang, language, language, letterSpacing, letterSpacing, letterSpacing, letterSpacingAsDouble, lightingColor, lightingColor, limitingConeAngle, limitingConeAngle, limitingConeAngle, limitingConeAngleAsDouble, list, list, local, local, loop, loop, loopAsBoolean, low, low, low, lowAsDouble, markerEnd, markerEnd, markerHeight, markerHeight, markerHeight, markerHeightAsDouble, markerMid, markerMid, markerStart, markerStart, markerUnits, markerUnits, markerWidth, markerWidth, markerWidth, markerWidthAsDouble, mask, mask, maskContentUnits, maskContentUnits, maskUnits, maskUnits, max, max, max, maxAsDouble, maxlength, maxlength, maxlength, maxlengthAsInt, media, media, method, method, min, min, min, minAsDouble, minlength, minlength, minlength, minlengthAsInt, mode, mode, multiple, multiple, multipleAsBoolean, muted, muted, mutedAsBoolean, name, name, novalidate, novalidate, novalidateAsBoolean, numOctaves, numOctaves, numOctaves, numOctavesAsInt, opacity, opacity, opacity, opacityAsDouble, open, open, openAsBoolean, operator, operator, optimum, optimum, optimum, optimumAsDouble, order, order, order, orderAsInt, overflow, overflow, overlinePosition, overlinePosition, overlinePosition, overlinePositionAsDouble, overlineThickness, overlineThickness, overlineThickness, overlineThicknessAsDouble, paintOrder, paintOrder, pathLength, pathLength, pathLength, pathLengthAsDouble, pattern, pattern, patternContentUnits, patternContentUnits, patternTransform, patternTransform, patternUnits, patternUnits, ping, ping, pingAsBoolean, placeholder, placeholder, plaindata, plaindata, pointerEvents, pointerEvents, points, points, pointsAtX, pointsAtX, pointsAtX, pointsAtXAsDouble, pointsAtY, pointsAtY, pointsAtY, pointsAtYAsDouble, pointsAtZ, pointsAtZ, pointsAtZ, pointsAtZAsDouble, poster, poster, preload, preload, preserveAlpha, preserveAlpha, preserveAspectRatio, preserveAspectRatio, primitiveUnits, primitiveUnits, r, r, r, radiogroup, radiogroup, radius, radius, radius, radiusAsDouble, rAsDouble, readonly, readonly, readonlyAsBoolean, refX, refX, refX, refXAsDouble, refy, refy, refy, refyAsDouble, rel, rel, repeatCount, repeatCount, repeatCount, repeatCountAsDouble, repeatDur, repeatDur, required, required, requiredAsBoolean, requiredFeatures, requiredFeatures, restart, restart, result, result, reversed, reversed, reversedAsBoolean, role, role, rows, rows, rows, rowsAsInt, rowspan, rowspan, rowspan, rowspanAsInt, rx, rx, rx, rxAsDouble, ry, ry, ry, ryAsDouble, sandbox, sandbox, scale, scale, scale, scaleAsDouble, scope, scope, seed, seed, seed, seedAsDouble, selected, selected, selectedAsBoolean, selectionDirection, selectionDirection, selectionEnd, selectionEnd, selectionEnd, selectionEndAsInt, selectionStart, selectionStart, selectionStart, selectionStartAsInt, shape, shape, shapeRendering, shapeRendering, size, size, size, sizeAsInt, sizes, sizes, slot, slot, span, span, span, spanAsInt, specularConstant, specularConstant, specularConstant, specularConstantAsDouble, specularExponent, specularExponent, specularExponent, specularExponentAsDouble, spellcheck, spellcheck, src, src, srcdoc, srcdoc, srclang, srclang, srcset, srcset, start, start, start, startAsInt, stdDeviation, stdDeviation, stdDeviation, stdDeviationAsDouble, step, step, step, stepAsDouble, stitchTiles, stitchTiles, stopColor, stopColor, stopOpacity, stopOpacity, stopOpacity, stopOpacityAsDouble, strikethroughPosition, strikethroughPosition, strikethroughPosition, strikethroughPositionAsDouble, strikethroughThickness, strikethroughThickness, strikethroughThickness, strikethroughThicknessAsDouble, stroke, stroke, strokeDasharray, strokeDasharray, strokeDashoffset, strokeDashoffset, strokeDashoffset, strokeDashoffsetAsDouble, strokeLinecap, strokeLinecap, strokeLinejoin, strokeLinejoin, strokeMiterlimit, strokeMiterlimit, strokeMiterlimit, strokeMiterlimitAsDouble, strokeOpacity, strokeOpacity, strokeOpacity, strokeOpacityAsDouble, strokeWidth, strokeWidth, strokeWidth, strokeWidthAsDouble, style, style, surfaceScale, surfaceScale, surfaceScale, surfaceScaleAsDouble, systemLanguage, systemLanguage, tabindex, tabindex, tabindex, tabindexAsInt, target, target, targetX, targetX, targetX, targetXAsDouble, targetY, targetY, targetY, targetYAsDouble, textAnchor, textAnchor, textDecoration, textDecoration, textLength, textLength, textLength, textLengthAsDouble, textRendering, textRendering, title, title, to, to, transform, transform, type, type, typemustmatch, typemustmatch, typemustmatchAsBoolean, underlinePosition, underlinePosition, underlinePosition, underlinePositionAsDouble, underlineThickness, underlineThickness, underlineThickness, underlineThicknessAsDouble, usemap, usemap, value, value, value, valueAsDouble, values, values, vectorEffect, vectorEffect, version, version, viewBox, viewBox, visibility, visibility, volume, volume, volume, volumeAsDouble, width, width, width, width, widthAsDouble, widthAsInt, wordSpacing, wordSpacing, wordSpacing, wordSpacingAsDouble, wrap, wrap, writingMode, writingMode, x, x, x, x1, x1, x1, x1AsDouble, x2, x2, x2, x2AsDouble, xAsDouble, xChannelSelector, xChannelSelector, y, y, y, y1, y1, y1, y1AsDouble, y2, y2, y2, y2AsDouble, yAsDouble, yChannelSelector, yChannelSelector, z, z, z, zAsDouble
-
Constructor Details
-
DomElement
-
DomElement
Creates deep unfrozen copy of another element.- Parameters:
-
other
- element to clone - Throws:
-
NullPointerException
- if the parameter isnull
-
-
Method Details
-
tagname
-
id
Gets element ID. This method returns element ID set viaid(String)
. ID isnull
by default.- Returns:
- element ID
-
id
Sets element's ID. Once set, the ID is available fromid()
method.Element ID is serialized as the
id
attribute in HTML. It must therefore fulfill criteria for proper element ID in HTML, which most importantly means the ID should be unique in the document. PushMode however doesn't check whether the ID is really unique and instead takes some steps to tolerate accidental duplicates. This method only checks for an empty string and treats it asnull
.Element ID has a special meaning in PushMode. Listeners require the element to have an ID. Listeners on ID-less elements are ignored. DOM diffing algorithm also uses ID when
key()
is not set.Internally, ID gets its own field in the class unlike other attributes. This makes access to ID much faster than access to other attributes.
- Parameters:
-
id
- new element ID - Returns:
-
this
- Throws:
-
IllegalStateException
- if element is frozen
-
key
Gets element's pairing key. This method returns element key set viakey(String)
.- Returns:
- element's key
-
key
Sets element's pairing key. Key, if set, must be unique among siblings in the DOM tree. Once set, the key is available fromkey()
.While
id()
is sent to the browser and it should be unique in the document,key()
is used only server-side and it only needs to be unique among sibling elements.Key is used in hierarchical DOM diff to pair corresponding elements in cases where some DOM nodes have been inserted or removed from parent's child list. If
key()
isnull
, DOM diff falls back to element'sid()
. If that isnull
too, DOM diff uses element position to pair elements in compared DOM trees, which might result in unnecessarily big diffs if an element is inserted at the beginning of a long list. Absence of key thus doesn't impact functionality, only performance. And even then it matters only if siblings are inserted or removed.- Parameters:
-
key
- new element key ornull
- Returns:
-
this
- Throws:
-
IllegalStateException
- if this element is frozen
-
rawAttributes
-
rawAttributes
-
unset
- Specified by:
-
unset
in interfaceDomAttributes
-
set
- Specified by:
-
set
in interfaceDomAttributes
-
set
- Specified by:
-
set
in interfaceDomAttributes
-
set
- Specified by:
-
set
in interfaceDomAttributes
-
set
- Specified by:
-
set
in interfaceDomAttributes
-
set
- Specified by:
-
set
in interfaceDomAttributes
-
set
- Specified by:
-
set
in interfaceDomAttributes
-
set
@NoDocs @DraftApi("should be probably Collection instead of Iterable") public DomElement set(Iterable<DomAttribute> attributes) -
set
-
attributes
- Specified by:
-
attributes
in interfaceDomAttributes
-
attribute
- Specified by:
-
attribute
in interfaceDomAttributes
-
attributeAsString
- Specified by:
-
attributeAsString
in interfaceDomAttributes
-
attributeAsBoolean
- Specified by:
-
attributeAsBoolean
in interfaceDomAttributes
-
attributeAsInt
- Specified by:
-
attributeAsInt
in interfaceDomAttributes
-
attributeAsDouble
- Specified by:
-
attributeAsDouble
in interfaceDomAttributes
-
rawListeners
-
rawListeners
-
subscribe
-
listeners
-
add
Adds new child node to this element.- Overrides:
-
add
in classDomContainer
- Parameters:
-
child
- node to add (ignored ifnull
) - Returns:
-
this
- Throws:
-
IllegalStateException
- if this element is frozen - See Also:
-
add
Adds all nodes in aCollection
to this element.- Overrides:
-
add
in classDomContainer
- Type Parameters:
-
C
- item type - Parameters:
-
children
- collection of child nodes to add (ignored ifnull
) - Returns:
-
this
- Throws:
-
IllegalStateException
- if this element is frozen - See Also:
-
add
Adds all nodes in aStream
to this element.- Overrides:
-
add
in classDomContainer
- Type Parameters:
-
C
- item type - Parameters:
-
children
-Stream
of child nodes to add (ignored ifnull
) - Returns:
-
this
- Throws:
-
IllegalStateException
- if this element is frozen - See Also:
-
add
Adds literal text to this element The text is first wrapped inDomText
. If the text is null or empty, this method has no effect. If there is already some text at the end of this element, this method replaces it with concatenation with the supplied text.- Overrides:
-
add
in classDomContainer
- Parameters:
-
text
- text to add (ignored ifnull
or empty) - Returns:
-
this
- Throws:
-
IllegalStateException
- if this element is frozen - See Also:
-
descendantsAndSelf
-
clone
Creates deep unfrozen clone of this element. All child nodes are cloned recursively. The clone is completely independent of this element.- Specified by:
-
clone
in classDomContainer
- Returns:
- deep mutable clone
-
equals
Compares two elements. This method comparestagname()
, link #id()},key()
, attributes, listeners, and element's children. Children are compared recursively by calling theirDomContent.equals(Object)
methods. If the only difference is that one of the elements is frozen and the other is not, this method returns true. Order of attributes and listeners is significant. Listeners must have identical callback pointers to compare equal.- Overrides:
-
equals
in classDomContainer
- Parameters:
-
object
- object to compare this element with - Returns:
-
true
if the two elements are equal,false
otherwise
-
hashCode
public int hashCode()Computes deep hash code of the element. Hash code changes withtagname()
, link #id()},key()
, attributes, listeners, and element's children Freezing the element doesn't change its hash code. Order of attributes and listeners is significant. Listeners must have identical callback pointers to have the same hash code.- Overrides:
-
hashCode
in classDomContainer
- Returns:
- hash code of the element
-
assign
-
freeze
Protects this element from further modification. For more information, use cases, and thread safety, seeDomContent.freeze()
.- Overrides:
-
freeze
in classDomContainer
- Returns:
-
this
-
toPoster
-
onclick
Adds event handler forclick
event. Single event can have multiple event handlers. This method adds new event handler to the end of the list. Event handlers are executed in order.- Parameters:
-
handler
- Event handler to add. Ifnull
, an empty event handler is added. - Returns:
-
this
-
onchange
Adds event handler forchange
event. Single event can have multiple event handlers. This method adds new event handler to the end of the list. Event handlers are executed in order.- Parameters:
-
handler
- Event handler to add. Ifnull
, an empty event handler is added. - Returns:
-
this
-
oninput
Adds event handler forinput
event. Single event can have multiple event handlers. This method adds new event handler to the end of the list. Event handlers are executed in order.- Parameters:
-
handler
- Event handler to add. Ifnull
, an empty event handler is added. - Returns:
-
this
-
checked
Sets up two-way binding on attributechecked
. Changes in the attribute are synchronized both ways between the client and the server. When parametervalue
changes between two invocations ofPushPage.document()
, the change is sent to the client. When user's actions cause the browser to change client-side value of the attribute, PushMode javascript sends the change to the server, which then invokes callback specified insetter
parameter.When
setter
completes, the next invocation ofPushPage.document()
should setvalue
parameter to the same value that was passed to thesetter
. If the value is different, PushMode assumes thatsetter
has performed coercion of the value. Coerced value is then sent to the client where it replaces user's input.Bindings require
id()
to be set. Bindings on elements withnull
ID are ignored.- Parameters:
-
value
- Server-supplied value of the attribute. -
setter
- Callback accepting the most recent value available on the client side. - Returns:
-
this
- Throws:
-
NullPointerException
- Thesetter
parameter isnull
.
-
checked
Sets up two-way binding on attributechecked
. Changes in the attribute are synchronized both ways between the client and the server. When parametervalue
changes between two invocations ofPushPage.document()
, the change is sent to the client. When user's actions cause the browser to change client-side value of the attribute, PushMode javascript sends the change to the server, which then invokes callback specified insetter
parameter.When
setter
completes, the next invocation ofPushPage.document()
should setvalue
parameter to the same value that was passed to thesetter
. If the value is different, PushMode assumes thatsetter
has performed coercion of the value. Coerced value is then sent to the client where it replaces user's input.Bindings require
id()
to be set. Bindings on elements withnull
ID are ignored.- Parameters:
-
value
- Server-supplied value of the attribute. Ifnull
,false
is substituted by this method. -
setter
- Callback accepting the most recent value available on the client side. - Returns:
-
this
- Throws:
-
NullPointerException
- Thesetter
parameter isnull
.
-
value
Sets up two-way binding on attributevalue
. Changes in the attribute are synchronized both ways between the client and the server. When parametervalue
changes between two invocations ofPushPage.document()
, the change is sent to the client. When user's actions cause the browser to change client-side value of the attribute, PushMode javascript sends the change to the server, which then invokes callback specified insetter
parameter.When
setter
completes, the next invocation ofPushPage.document()
should setvalue
parameter to the same value that was passed to thesetter
. If the value is different, PushMode assumes thatsetter
has performed coercion of the value. Coerced value is then sent to the client where it replaces user's input.Bindings require
id()
to be set. Bindings on elements withnull
ID are ignored.- Parameters:
-
value
- Server-supplied value of the attribute. Ifnull
, empty string is substituted by this method. -
setter
- Callback accepting the most recent value available on the client side. - Returns:
-
this
- Throws:
-
NullPointerException
- Thesetter
parameter isnull
.
-
fromXml
-
fromXml
-