public abstract class MarkupContainer extends Component implements Iterable<Component>
add(Component...)
method, and
they can be looked up using a colon separated path. For example, if a container called "a" held a
nested container "b" which held a nested component "c", then a.get("b:c") would return the
Component with id "c". The number of children in a MarkupContainer can be determined by calling
size(), and the whole hierarchy of children held by a MarkupContainer can be traversed by calling
visitChildren(), passing in an implementation of IVisitor.
Components may alter their referring tag, replace the tag's body or insert markup after the tag. But components cannot remove tags from the markup stream. This is an important guarantee because graphic designers may be setting attributes on component tags that affect visual presentation.
The type of markup held in a given container subclass can be determined by calling
getMarkupType()
. Markup is accessed via a MarkupStream object which allows a component
to traverse ComponentTag and RawMarkup MarkupElements while rendering a response. Markup in the
stream may be HTML or some other kind of markup, such as VXML, as determined by the specific
container subclass.
A markup stream may be directly associated with a container via setMarkupStream. However, a
container which does not have a markup stream (its getMarkupStream() returns null) may inherit a
markup stream from a container above it in the component hierarchy. The
Component.findMarkupStream()
method will locate the first container at or above this container
which has a markup stream.
All Page containers set a markup stream before rendering by calling the method
getAssociatedMarkupStream(boolean)
to load the markup associated with the page. Since
Page is at the top of the container hierarchy, it is guaranteed that Component.findMarkupStream()
will always return a valid markup stream.
MarkupStream
,
Serialized FormENABLE, FLAG_AFTER_RENDERING, FLAG_INITIALIZED, FLAG_PREPARED_FOR_RENDER, FLAG_REMOVING_FROM_HIERARCHY, FLAG_RENDERING, FLAG_RESERVED1, FLAG_RESERVED2, FLAG_RESERVED3, FLAG_RESERVED4, FLAG_RESERVED5, FLAG_RESERVED8, PARENT_PATH, PATH_SEPARATOR, RENDER, RFLAG_CONTAINER_DEQUEING
Constructor and Description |
---|
MarkupContainer(String id) |
MarkupContainer(String id,
IModel<?> model) |
Modifier and Type | Method and Description |
---|---|
MarkupContainer |
add(Component... children)
Adds the child component(s) to this container.
|
protected void |
addDequeuedComponent(Component component,
ComponentTag tag)
Adds a dequeued component to this container.
|
MarkupContainer |
addOrReplace(Component... children)
Replaces a child component of this container with another or just adds it in case no child
with the same id existed yet.
|
boolean |
autoAdd(Component component,
MarkupStream markupStream)
This method allows a component to be added by an auto-resolver such as AutoLinkResolver.
|
protected DequeueTagAction |
canDequeueTag(ComponentTag tag)
Checks if this container can dequeue a child represented by the specified tag.
|
boolean |
contains(Component component,
boolean recurse) |
void |
dequeue() |
void |
dequeue(DequeueContext dequeue)
Dequeues components.
|
protected void |
dequeuePreamble(DequeueContext dequeue)
Run preliminary operations before running
dequeue(DequeueContext) . |
protected Component |
findChildComponent(ComponentTag tag)
Search the child component for the given tag.
|
Component |
findComponentToDequeue(ComponentTag tag)
Queries this container to find a child that can be dequeued that matches the specified tag.
|
Component |
get(int index)
Deprecated.
this method is marked for deletion for WICKET8
|
Component |
get(String path)
Get a child component by looking it up with the given path.
|
Markup |
getAssociatedMarkup()
Gets a fresh markup stream that contains the (immutable) markup resource for this class.
|
MarkupStream |
getAssociatedMarkupStream(boolean throwException)
Gets a fresh markup stream that contains the (immutable) markup resource for this class.
|
IMarkupFragment |
getMarkup(Component child)
Get the markup of the child.
|
MarkupType |
getMarkupType()
Get the type of associated markup for this component.
|
IMarkupFragment |
getRegionMarkup() |
void |
internalAdd(Component child)
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.
|
void |
internalInitialize()
THIS METHOD IS NOT PART OF THE PUBLIC API, DO NOT CALL IT
Overrides
Component.internalInitialize() to call Component.fireInitialize()
for itself and for all its children. |
Iterator<Component> |
iterator()
Gives an iterator that allow you to iterate through the children of this markup container in
the order the children were added.
|
Iterator<Component> |
iterator(Comparator<Component> comparator)
Creates an iterator that iterates over children in the order specified by comparator.
|
DequeueContext |
newDequeueContext() |
protected void |
onAfterRenderChildren() |
void |
onComponentTagBody(MarkupStream markupStream,
ComponentTag openTag)
Handle the container's body.
|
protected void |
onDetach()
Called to allow a component to detach resources after use.
|
protected void |
onInitialize()
This method is meant to be used as an alternative to initialize components.
|
protected void |
onRender()
Implementation that renders this component.
|
MarkupContainer |
queue(Component... components)
Queues one or more components to be dequeued later.
|
MarkupContainer |
remove(Component component)
Removes a component from the children identified by the
component.getId() |
MarkupContainer |
remove(String id)
Removes the given component
|
MarkupContainer |
removeAll()
Removes all children from this container.
|
protected void |
renderAll(MarkupStream markupStream,
ComponentTag openTag)
Loop through the markup in this container
|
void |
renderAssociatedMarkup(String openTagName,
String exceptionMessage)
Renders the entire associated markup for a container such as a Border or Panel.
|
protected boolean |
renderNext(MarkupStream markupStream)
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API.
|
MarkupContainer |
replace(Component child)
Replaces a child component of this container with another
|
MarkupContainer |
setDefaultModel(IModel<?> model)
Sets the given model.
|
int |
size()
Get the number of children in this container.
|
void |
swap(int idx1,
int idx2)
Deprecated.
this method is marked for deletion for WICKET8
|
String |
toString()
Gets the string representation of this component.
|
String |
toString(boolean detailed) |
ComponentHierarchyIterator |
visitChildren()
Deprecated.
ComponentHierarchyIterator is deprecated.
Use
visitChildren(org.apache.wicket.util.visit.IVisitor) instead |
ComponentHierarchyIterator |
visitChildren(Class<?> clazz)
Deprecated.
ComponentHierarchyIterator is deprecated.
Use
visitChildren(Class, org.apache.wicket.util.visit.IVisitor) instead. |
<S extends Component,R> |
visitChildren(Class<?> clazz,
IVisitor<S,R> visitor)
Traverses all child components of the given class in this container, calling the visitor's
visit method at each one.
|
<R> R |
visitChildren(IVisitor<Component,R> visitor)
Traverses all child components in this container, calling the visitor's visit method at each
one.
|
add, addStateChange, afterRender, beforeRender, canCallListenerInterface, canCallListenerInterfaceAfterExpiry, checkComponentTag, checkComponentTagAttribute, checkHierarchyChange, clearOriginalDestination, configure, continueToOriginalDestination, createConverter, debug, detach, detachModel, detachModels, determineVisibility, error, exceptionMessage, fatal, findMarkupStream, findPage, findParent, findParentWithAssociatedMarkup, getAjaxRegionMarkupId, getApplication, getBehaviorById, getBehaviorId, getBehaviors, getBehaviors, getClassRelativePath, getConverter, getDefaultModel, getDefaultModelObject, getDefaultModelObjectAsString, getDefaultModelObjectAsString, getEscapeModelStrings, getFeedbackMessages, getFlag, getId, getInnermostModel, getInnermostModel, getLocale, getLocalizer, getMarkup, getMarkupAttributes, getMarkupId, getMarkupId, getMarkupIdFromMarkup, getMarkupIdImpl, getMarkupSourcingStrategy, getMetaData, getModelComparator, getOutputMarkupId, getOutputMarkupPlaceholderTag, getPage, getPageRelativePath, getParent, getPath, getRenderBodyOnly, getRequest, getRequestCycle, getRequestFlag, getResponse, getSession, getSizeInBytes, getStatelessHint, getString, getString, getString, getStyle, getVariation, hasBeenRendered, hasErrorMessage, hasFeedbackMessage, info, initModel, internalOnModelChanged, internalPrepareForRender, internalRenderComponent, internalRenderHead, isActionAuthorized, isAuto, isBehaviorAccepted, isEnableAllowed, isEnabled, isEnabledInHierarchy, isIgnoreAttributeModifier, isRenderAllowed, isRendering, isStateless, isVersioned, isVisibilityAllowed, isVisible, isVisibleInHierarchy, markRendering, modelChanged, modelChanging, newMarkupSourcingStrategy, onAfterRender, onBeforeRender, onComponentTag, onConfigure, onEvent, onModelChanged, onModelChanging, onReAdd, onRemove, prepareForRender, redirectToInterceptPage, remove, remove, render, renderComponentTag, rendered, renderHead, renderHead, renderPlaceholderTag, replaceComponentTagBody, replaceWith, sameInnermostModel, sameInnermostModel, send, setAuto, setDefaultModelObject, setEnabled, setEscapeModelStrings, setFlag, setIgnoreAttributeModifier, setMarkup, setMarkupId, setMarkupIdImpl, setMetaData, setOutputMarkupId, setOutputMarkupPlaceholderTag, setParent, setRenderBodyOnly, setRequestFlag, setResponsePage, setResponsePage, setResponsePage, setVersioned, setVisibilityAllowed, setVisible, success, urlFor, urlFor, urlFor, urlFor, urlFor, visitParents, visitParents, warn, wrap
public MarkupContainer(String id)
Component.Component(String)
public MarkupContainer(String id, IModel<?> model)
Component.Component(String, IModel)
public MarkupContainer add(Component... children)
children
- The child(ren) to add.IllegalArgumentException
- Thrown if a child with the same id is replaced by the add operation.public MarkupContainer addOrReplace(Component... children)
children
- The child(ren) to be added or replacedpublic final boolean autoAdd(Component component, MarkupStream markupStream)
The result of all this is that components added with autoAdd() are free from versioning and can add their own children without the usual exception that would normally be thrown when the component hierarchy is modified during rendering.
component
- The component to addmarkupStream
- Null, if the parent container is able to provide the markup. Else the markup
stream to be used to render the component.public boolean contains(Component component, boolean recurse)
component
- The component to checkrecurse
- True if all descendents should be consideredpublic final Component get(String path)
A component path consists of component ids separated by colons, e.g. "b:c" identifies a component "c" inside container "b" inside this container.
get
in interface IRequestableComponent
get
in class Component
path
- path to componentpublic MarkupStream getAssociatedMarkupStream(boolean throwException)
throwException
- If true, throw an exception, if markup could not be foundpublic Markup getAssociatedMarkup()
public IMarkupFragment getMarkup(Component child)
child
- The child component. If null, the container's markup will be returned. See Border,
Panel or Enclosure where getMarkup(null) != getMarkup().Component.getMarkup()
public MarkupType getMarkupType()
public void internalAdd(Component child)
child
- The childIllegalArgumentException
- Thrown if a child with the same id is replaced by the add operation.public Iterator<Component> iterator()
public final Iterator<Component> iterator(Comparator<Component> comparator)
comparator
- The comparatorpublic MarkupContainer remove(Component component)
component.getId()
component
- Component to remove from this containerthis
for chainingpublic MarkupContainer remove(String id)
id
- The id of the component to removethis
for chainingpublic MarkupContainer removeAll()
Note: implementation does not call remove(Component)
for each
component.
this
for method chainingpublic final void renderAssociatedMarkup(String openTagName, String exceptionMessage)
openTagName
- the tag to render the associated markup forexceptionMessage
- message that will be used for exceptionspublic MarkupContainer replace(Component child)
child
- The childIllegalArgumentException
- Thrown if there was no child with the same id.public MarkupContainer setDefaultModel(IModel<?> model)
Component
WARNING: DO NOT OVERRIDE THIS METHOD UNLESS YOU HAVE A VERY GOOD REASON FOR IT. OVERRIDING THIS MIGHT OPEN UP SECURITY LEAKS AND BREAK BACK-BUTTON SUPPORT.
setDefaultModel
in class Component
model
- The modelComponent.setDefaultModel(org.apache.wicket.model.IModel)
public int size()
public String toString()
Component
toString
in class Component
Component.toString()
public String toString(boolean detailed)
public final <S extends Component,R> R visitChildren(Class<?> clazz, IVisitor<S,R> visitor)
S
- The type that goes into the Visitor.component() method.R
- clazz
- The class of child to visitvisitor
- The visitor to call back topublic final <R> R visitChildren(IVisitor<Component,R> visitor)
R
- visitor
- The visitor to call back to@Deprecated public final ComponentHierarchyIterator visitChildren()
visitChildren(org.apache.wicket.util.visit.IVisitor)
instead@Deprecated public final ComponentHierarchyIterator visitChildren(Class<?> clazz)
visitChildren(Class, org.apache.wicket.util.visit.IVisitor)
instead.clazz
- Filter conditionpublic final void internalInitialize()
Component.internalInitialize()
to call Component.fireInitialize()
for itself and for all its children.internalInitialize
in class Component
Component.fireInitialize()
@Deprecated public final Component get(int index)
index
- the index of the child in this containerArrayIndexOutOfBoundsException
- when index
exceeds size()
protected boolean renderNext(MarkupStream markupStream)
markupStream
- The markup streampublic void onComponentTagBody(MarkupStream markupStream, ComponentTag openTag)
onComponentTagBody
in class Component
markupStream
- The markup streamopenTag
- The open tag for the bodyprotected void onRender()
Component
onRender
in class Component
Component.onRender()
protected final void renderAll(MarkupStream markupStream, ComponentTag openTag)
markupStream
- openTag
- protected void onAfterRenderChildren()
onAfterRenderChildren
in class Component
@Deprecated public final void swap(int idx1, int idx2)
idx1
- index of first component to be swappedidx2
- index of second component to be swappedprotected void onDetach()
Component
public MarkupContainer queue(Component... components)
add(Component...)
method is that the component does not have to be added to its
direct parent, only to a parent upstream; it will be dequeued into the correct parent using
the hierarchy defined in the markup. This allows the component hierarchy to be maintained only
in markup instead of in markup and in java code; affording designers and developers more
freedom when moving components in markup.components
- the components to queuethis
for method chainingpublic void dequeue()
IQueueRegion.dequeue()
protected void onInitialize()
Component
Page
thus providing the component with an atomic callback
when the component's environment is built out.
Overrides must call super#Component.onInitialize()
. Usually this should be the first thing an
override does, much like a constructor.
Parent containers are guaranteed to be initialized before their children
It is safe to use Component.getPage()
in this method
NOTE:The timing of this call is not precise, the contract is that it is called sometime
before Component.onBeforeRender()
.
onInitialize
in class Component
protected void dequeuePreamble(DequeueContext dequeue)
dequeue(DequeueContext)
. More in detail it
throws an exception if the container is already dequeuing, and it also takes care of setting
flag RFLAG_CONTAINER_DEQUEING
to true before running dequeue(DequeueContext)
and setting it back to false after dequeuing is completed.dequeue
- the dequeue context to usepublic void dequeue(DequeueContext dequeue)
queue(Component...)
. It then delegates the
dequeueing to these children.
Certain components that implement custom markup behaviors (such as repeaters and borders)
override this method to bring dequeueing in line with their custom markup handling.dequeue
- the dequeue context to useprotected Component findChildComponent(ComponentTag tag)
tag
- the component tagpublic DequeueContext newDequeueContext()
IQueueRegion.newDequeueContext()
public IMarkupFragment getRegionMarkup()
IQueueRegion.getRegionMarkup()
protected DequeueTagAction canDequeueTag(ComponentTag tag)
ComponentTag
s are supported as well as WicketTag
s that return
a non-null value from ComponentTag.getAutoComponentFactory()
method.tag
- public Component findComponentToDequeue(ComponentTag tag)
tag
- protected void addDequeuedComponent(Component component, ComponentTag tag)
MarkupContainer#add(Component...))
method should cover most cases. Components that
implement a custom hierarchy, such as borders, may wish to override it to support edge-case
non-standard behavior.component
- tag
- Copyright © 2006–2020 Apache Software Foundation. All rights reserved.