Class SharedTagContent<T>
java.lang.Object
com.webfirmframework.wffweb.tag.html.SharedTagContent<T>
- Type Parameters:
T
- class type of content in this SharedTagContent object
This class is highly thread-safe so you can even declare a static object to
use under multiple threads. Changing the content of this object will be
reflected in all consuming tags if shared property of this object is true.
The shared property can be set as by passing constructor argument or by
setter method. Its default value is true if not explicitly specified.
Usage Eg:-
Usage Eg:-
SharedTagContent<String> stc = new SharedTagContent<>("Initial Content"); Div div = new Div(null); Span span1 = new Span(div); span1.subscribeTo(stc); Span span2 = new Span(div); span2.addInnerHtml(stc); System.out.println(div.toHtmlString()); stc.setContent("Content Changed"); System.out.println(div.toHtmlString());prints
<div><span>Initial Content</span><span>Initial Content</span></div> <div><span>Content Changed</span><span>Content Changed</span></div>
- Since:
- 3.0.6
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
static final class
This is a serializable record class for handling content inSharedTagContent
object.static interface
static interface
static final class
static interface
static enum
Represents the behavior of push operation of BrowserPage to client. -
Constructor Summary
ConstructorDescriptionSharedTagContent
(boolean shared, T content) SharedTagContent
(boolean shared, T content, boolean contentTypeHtml) SharedTagContent
(SharedTagContent.UpdateClientNature updateClientNature, boolean shared, T content) SharedTagContent
(SharedTagContent.UpdateClientNature updateClientNature, boolean shared, T content, boolean contentTypeHtml) or null if no preference.SharedTagContent
(SharedTagContent.UpdateClientNature updateClientNature, T content) SharedTagContent
(SharedTagContent.UpdateClientNature updateClientNature, T content, boolean contentTypeHtml) SharedTagContent
(Executor executor, boolean shared, T content) SharedTagContent
(Executor executor, boolean shared, T content, boolean contentTypeHtml) SharedTagContent
(Executor executor, SharedTagContent.UpdateClientNature updateClientNature, boolean shared, T content) SharedTagContent
(Executor executor, SharedTagContent.UpdateClientNature updateClientNature, boolean shared, T content, boolean contentTypeHtml) SharedTagContent
(Executor executor, SharedTagContent.UpdateClientNature updateClientNature, T content) SharedTagContent
(Executor executor, SharedTagContent.UpdateClientNature updateClientNature, T content, boolean contentTypeHtml) SharedTagContent
(Executor executor, T content) plain text content with updateClientNature as UpdateClientNature.ALLOW_ASYNC_PARALLEL.SharedTagContent
(Executor executor, T content, boolean contentTypeHtml) The default value of updateClientNature is UpdateClientNature.ALLOW_ASYNC_PARALLEL.SharedTagContent
(T content) plain text content with updateClientNature as UpdateClientNature.ALLOW_ASYNC_PARALLEL.SharedTagContent
(T content, boolean contentTypeHtml) The default value of updateClientNature is UpdateClientNature.ALLOW_ASYNC_PARALLEL. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addContentChangeListener
(AbstractHtml tag, SharedTagContent.ContentChangeListener<T> contentChangeListener) void
addDetachListener
(AbstractHtml tag, SharedTagContent.DetachListener<T> detachListener) void
Clears the unwanted objects from the temporary cache only if required.void
detach
(boolean removeContent) void
detach
(boolean removeContent, Set<AbstractHtml> exclusionTags) void
detach
(boolean removeContent, Set<AbstractHtml> exclusionTags, Set<AbstractHtml> exclusionClientUpdateTags) void
detach
(Set<AbstractHtml> exclusionTags) Detaches without removing contents from consuming tags.RefersetUpdateClientNature(UpdateClientNature)
for more details.boolean
boolean
isShared()
boolean
its default value is true if not explicitly setvoid
all listeners will be removed from all tagsvoid
void
all listeners will be removed from all tagsvoid
void
removeContentChangeListener
(AbstractHtml tag, SharedTagContent.ContentChangeListener<T> contentChangeListener) void
removeContentChangeListener
(SharedTagContent.ContentChangeListener<T> contentChangeListener) NB: this method will traverse through all consumer tags of this SharedTagContent instance.void
removeContentChangeListeners
(AbstractHtml tag, Collection<SharedTagContent.ContentChangeListener<T>> contentChangeListeners) void
removeDetachListener
(AbstractHtml tag, SharedTagContent.DetachListener<T> detachListener) void
removeDetachListener
(SharedTagContent.DetachListener<T> detachListener) NB: this method will traverse through all consumer tags of this SharedTagContent instance.void
removeDetachListeners
(AbstractHtml tag, Collection<SharedTagContent.DetachListener<T>> detachListeners) void
setContent
(SharedTagContent.UpdateClientNature updateClientNature, T content) void
setContent
(SharedTagContent.UpdateClientNature updateClientNature, T content, boolean contentTypeHtml) void
setContent
(Set<AbstractHtml> exclusionTags, T content) void
setContent
(Set<AbstractHtml> exclusionTags, T content, boolean contentTypeHtml) void
setContent
(T content) void
setContent
(T content, boolean contentTypeHtml) void
setExecutor
(Executor executor) void
setShared
(boolean shared) void
setUpdateClient
(boolean updateClient) void
setUpdateClientNature
(SharedTagContent.UpdateClientNature updateClientNature)
-
Constructor Details
-
SharedTagContent
plain text content with updateClientNature as UpdateClientNature.ALLOW_ASYNC_PARALLEL.- Parameters:
executor
- the executor object for async push or null if no preference. This executor object will be used only if theupdateClientNature
isSharedTagContent.UpdateClientNature.ALLOW_ASYNC_PARALLEL
orSharedTagContent.UpdateClientNature.ALLOW_PARALLEL
.
NB: You may need only one copy of executor object for all sharedTagContent instances in the project. So it could be declared as a static final object. Eg:
public static final Executor EXECUTOR = Executors.newCachedThreadPool(); sharedTagContent.setExecutor(EXECUTOR);
public static final Executor EXECUTOR = Executors.newVirtualThreadExecutor(); sharedTagContent.setExecutor(EXECUTOR);
content
- the content its content type will be considered as plain text, i.e. contentTypeHtml will be false.- Since:
- 3.0.15
-
SharedTagContent
plain text content with updateClientNature as UpdateClientNature.ALLOW_ASYNC_PARALLEL.- Parameters:
content
- the content its content type will be considered as plain text, i.e. contentTypeHtml will be false.- Since:
- 3.0.6
-
SharedTagContent
The default value of updateClientNature is UpdateClientNature.ALLOW_ASYNC_PARALLEL.- Parameters:
content
- the content to embed in the consumer tags.contentTypeHtml
- true to treat the given content as HTML otherwise false.- Since:
- 3.0.6
-
SharedTagContent
The default value of updateClientNature is UpdateClientNature.ALLOW_ASYNC_PARALLEL.- Parameters:
executor
- the executor object for async push or null if no preference. This executor object will be used only if theupdateClientNature
isSharedTagContent.UpdateClientNature.ALLOW_ASYNC_PARALLEL
orSharedTagContent.UpdateClientNature.ALLOW_PARALLEL
.
NB: You may need only one copy of executor object for all sharedTagContent instances in the project. So it could be declared as a static final object. Eg:
public static final Executor EXECUTOR = Executors.newCachedThreadPool(); sharedTagContent.setExecutor(EXECUTOR);
public static final Executor EXECUTOR = Executors.newVirtualThreadExecutor(); sharedTagContent.setExecutor(EXECUTOR);
content
- the content to embed in the consumer tags.contentTypeHtml
- true to treat the given content as HTML otherwise false.- Since:
- 3.0.15
-
SharedTagContent
- Parameters:
shared
- true to share its content across all consuming tags whensetContent(T)
is called.content
- the content to embed in the consumer tags.contentTypeHtml
- true to treat the given content as HTML otherwise false.- Since:
- 3.0.6
-
SharedTagContent
- Parameters:
executor
- the executor object for async push or null if no preference. This executor object will be used only if theupdateClientNature
isSharedTagContent.UpdateClientNature.ALLOW_ASYNC_PARALLEL
orSharedTagContent.UpdateClientNature.ALLOW_PARALLEL
.
NB: You may need only one copy of executor object for all sharedTagContent instances in the project. So it could be declared as a static final object. Eg:
public static final Executor EXECUTOR = Executors.newCachedThreadPool(); sharedTagContent.setExecutor(EXECUTOR);
public static final Executor EXECUTOR = Executors.newVirtualThreadExecutor(); sharedTagContent.setExecutor(EXECUTOR);
shared
- true to share its content across all consuming tags whensetContent(T)
is called.content
- the content to embed in the consumer tags.contentTypeHtml
- true to treat the given content as HTML otherwise false.- Since:
- 3.0.15
-
SharedTagContent
- Parameters:
shared
- true to share its content across all consuming tags whensetContent(T)
is called.content
- the content which will be treated as plain text in the consumer tags.- Since:
- 3.0.6
-
SharedTagContent
- Parameters:
executor
- the executor object for async push or null if no preference. This executor object will be used only if theupdateClientNature
isSharedTagContent.UpdateClientNature.ALLOW_ASYNC_PARALLEL
orSharedTagContent.UpdateClientNature.ALLOW_PARALLEL
.
NB: You may need only one copy of executor object for all sharedTagContent instances in the project. So it could be declared as a static final object. Eg:
public static final Executor EXECUTOR = Executors.newCachedThreadPool(); sharedTagContent.setExecutor(EXECUTOR);
public static final Executor EXECUTOR = Executors.newVirtualThreadExecutor(); sharedTagContent.setExecutor(EXECUTOR);
shared
- true to share its content across all consuming tags whensetContent(T)
is called.content
- the content which will be treated as plain text in the consumer tags.- Since:
- 3.0.15
-
Method Details
-
getContent
- Returns:
- the content
- Since:
- 3.0.6
-
isContentTypeHtml
public boolean isContentTypeHtml()- Returns:
- true if content type is HTML
- Since:
- 3.0.6
-
getUpdateClientNature
RefersetUpdateClientNature(UpdateClientNature)
for more details.- Returns:
- UpdateClientNature which specifies the nature.
- Since:
- 3.0.6
-
isUpdateClient
public boolean isUpdateClient()its default value is true if not explicitly set- Returns:
- true if updating client browser page is turned off
- Since:
- 3.0.6
-
getExecutor
- Returns:
- the Executor object.
- Since:
- 3.0.15
-
setUpdateClient
public void setUpdateClient(boolean updateClient) - Parameters:
updateClient
- true to turn on updating client browser page. By default it is true.- Since:
- 3.0.6
-
setExecutor
- Parameters:
executor
- the executor object for async push or null if no preference. This executor object will be used only if theupdateClientNature
isSharedTagContent.UpdateClientNature.ALLOW_ASYNC_PARALLEL
orSharedTagContent.UpdateClientNature.ALLOW_PARALLEL
.
NB: You may need only one copy of executor object for all sharedTagContent instances in the project. So it could be declared as a static final object. Eg:
public static final Executor EXECUTOR = Executors.newCachedThreadPool(); sharedTagContent.setExecutor(EXECUTOR);
public static final Executor EXECUTOR = Executors.newVirtualThreadExecutor(); sharedTagContent.setExecutor(EXECUTOR);
- Since:
- 3.0.15
-
setContent
- Parameters:
content
- content to be reflected in all consuming tags.- Since:
- 3.0.6
-
setContent
- Parameters:
content
- content to be reflected in all consuming tagscontentTypeHtml
- true if the content type is HTML or false if plain text- Since:
- 3.0.6
-
setContent
- Parameters:
exclusionTags
- tags to be excluded only from client update. It means that the content of all consumer tags will be kept updated at server side so their content content formatter and change listeners will be invoked.content
-- Since:
- 3.0.6
-
setContent
- Parameters:
exclusionTags
- tags to be excluded only from client update. It means that the content of all consumer tags will be kept updated at server side so their content content formatter and change listeners will be invoked.content
-contentTypeHtml
-- Since:
- 3.0.6
-
detach
Detaches without removing contents from consuming tags.- Parameters:
exclusionTags
- excluded tags from detachment of this SharedTagConent object- Since:
- 3.0.6
-
detach
public void detach(boolean removeContent) - Parameters:
removeContent
- true to remove content from the attached tags or false not to remove but will detach- Since:
- 3.0.6
-
detach
- Parameters:
removeContent
- true to remove content from the attached tags or false not to remove but will detachexclusionTags
- excluded tags from detachment of this SharedTagConent object- Since:
- 3.0.6
-
detach
public void detach(boolean removeContent, Set<AbstractHtml> exclusionTags, Set<AbstractHtml> exclusionClientUpdateTags) - Parameters:
removeContent
- true to remove content from the attached tags or false not to remove but will detachexclusionTags
- excluded tags from detachment of this SharedTagConent objectexclusionClientUpdateTags
- these tags will be excluded for client update- Since:
- 3.0.6
-
removeContentChangeListeners
public void removeContentChangeListeners(AbstractHtml tag, Collection<SharedTagContent.ContentChangeListener<T>> contentChangeListeners) - Parameters:
tag
- the tag from which the listener to be removedcontentChangeListeners
- to be removed- Since:
- 3.0.6
-
removeDetachListeners
public void removeDetachListeners(AbstractHtml tag, Collection<SharedTagContent.DetachListener<T>> detachListeners) - Parameters:
tag
-detachListeners
-- Since:
- 3.0.6
-
removeAllContentChangeListeners
- Parameters:
tag
- the tag from which all listeners to be removed- Since:
- 3.0.6
-
removeAllContentChangeListeners
public void removeAllContentChangeListeners()all listeners will be removed from all tags- Since:
- 3.0.6
-
removeAllDetachListeners
- Parameters:
tag
- the tag from which all listeners to be removed- Since:
- 3.0.6
-
removeAllDetachListeners
public void removeAllDetachListeners()all listeners will be removed from all tags- Since:
- 3.0.6
-
getContentFormatter
- Parameters:
tag
- the tag whose ContentFormatter to be got.- Returns:
- the ContentFormatter object set for the given tag.
- Since:
- 3.0.11
-
getContentChangeListeners
- Parameters:
tag
- tag from which the listeners to be got.- Returns:
- the ContentChangeListeners for the given tag.
- Since:
- 3.0.11
-
getDetachListeners
- Parameters:
tag
- tag from which the listeners to be got.- Returns:
- the DetachListeners for the given tag.
- Since:
- 3.0.11
-
clearTempCache
public void clearTempCache()Clears the unwanted objects from the temporary cache only if required. The unwanted objects are automatically cleared from the temp cache but this method is for manually clearing it.- Since:
- 3.0.18
-