com.vaadin.flow.component.
Class Html
- java.lang.Object
-
- com.vaadin.flow.component.Component
-
- com.vaadin.flow.component.Html
-
All Implemented Interfaces:
public class Html extends Component
A component which encapsulates a given HTML fragment with a single root element.
Note that it is the developer's responsibility to sanitize and remove any dangerous parts of the HTML before sending it to the user through this component. Passing raw input data to the user will possibly lead to cross-site scripting attacks.
This component does not expand the HTML fragment into a server side DOM tree so you cannot traverse or modify the HTML on the server. The root element can be accessed through
Component.getElement()
and the inner HTML throughgetInnerHtml()
.The HTML fragment cannot be changed after creation. You should create a new instance to encapsulate another fragment.
Since:
1.0
Author:
Vaadin Ltd
See Also:
-
-
Constructor Summary
Constructors Constructor and Description Html(InputStream stream)
Creates an instance based on the HTML fragment read from the stream.
Html(String outerHtml)
Creates an instance based on the given HTML fragment.
-
Method Summary
All Methods Modifier and Type Method and Description String
getInnerHtml()
Gets the inner HTML, i.e.
-
Methods inherited from class com.vaadin.flow.component.Component
addListener, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getLocale, getParent, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onAttach, onDetach, onEnabledStateChanged, set, setElement, setId, setVisible
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListener
-
Methods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListener
-
-
-
-
Constructor Detail
-
Html
public Html(InputStream stream)
Creates an instance based on the HTML fragment read from the stream. The fragment must have exactly one root element.
A best effort is done to parse broken HTML but no guarantees are given for how invalid HTML is handled.
Any heading or trailing whitespace is removed while parsing but any whitespace inside the root tag is preserved.
Parameters:
stream
- the input stream which provides the HTML in UTF-8Throws:
UncheckedIOException
- if reading the stream fails
-
Html
public Html(String outerHtml)
Creates an instance based on the given HTML fragment. The fragment must have exactly one root element.
A best effort is done to parse broken HTML but no guarantees are given for how invalid HTML is handled.
Any heading or trailing whitespace is removed while parsing but any whitespace inside the root tag is preserved.
Parameters:
outerHtml
- the HTML to wrap
-
-
Method Detail
-
getInnerHtml
public String getInnerHtml()
Gets the inner HTML, i.e. everything inside the root element.
Returns:
the inner HTML, not
null
-
-