package org.apache.wicket;
A MarkupContainer holds a map of child components.
- Children - Children can be added by calling the add() method, and they can be looked
up using a dotted 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 Component.IVisitor.
- Markup Rendering - A MarkupContainer also holds/references associated markup which is
used to render the container. As the markup stream for a container is rendered, component
references in the markup are resolved by using the container to look up Components in the
container's component map by id. Each component referenced by the markup stream is given an
opportunity to render itself using the markup stream.
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 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() to load the markup associated with the page. Since Page is at the top
of the container hierarchy, it is guaranteed that findMarkupStream will always return a valid
markup stream.
List of children or single child
The markup stream for this container. This variable is used only during the render phase to
provide access to the current element within the stream.
Adds a child component to this container.
child.getId() + "' already exists"));
Replaces a child component of this container with another or just adds it in case no child
with the same id existed yet.
- Parameters:
child
The child- Returns:
- This
This method allows a component to be added by an auto-resolver such as AutoComponentResolver
or AutoLinkResolver. While the component is being added, the component's FLAG_AUTO boolean is
set. The isAuto() method of Component returns true if a component or any of its parents has
this bit set. When a component is added via autoAdd(), the logic in Page that normally (a)
checks for modifications during the rendering process, and (b) versions components, is
bypassed if Component.isAuto() returns true.
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.
- Parameters:
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.- Returns:
- True, if component has been added
if (markupStream == null)
component.render(markupStream);
- Parameters:
component
The component to checkrecurse
True if all descendents should be considered- Returns:
- True if the component is contained in this container
for (Component current = component; current != null;)
Get a child component by looking it up with the given path.
- Parameters:
path
Path to component- Returns:
- The component at the path
Gets a fresh markup stream that contains the (immutable) markup resource for this class.
- Parameters:
throwException
If true, throw an exception, if markup could not be found- Returns:
- A stream of MarkupElement elements
" Enable debug messages for org.apache.wicket.util.resource to get a list of all filenames tried"),
Get the markup stream set on this container.
- Returns:
- Returns the markup stream set on this container.
Get the type of associated markup for this component.
- Returns:
- The type of associated markup for this component (for example, "html", "wml" or
"vxml"). The markup type for a component is independent of whether or not the
component actually has an associated markup resource file (which is determined at
runtime). If there is no markup type for a component, null may be returned, but this
means that no markup can be loaded for the class.
THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT USE IT.
Adds a child component to this container.
Some MarkupContainers (e.g. HtmlHeaderContainer) have to be transparent with respect to their
child components. A transparent container gets its children from its parent container.
- Returns:
- Iterator that iterates through children in the order they were added
- Parameters:
comparator
The comparator- Returns:
- Iterator that iterates over children in the order specified by comparator
Collections.sort(sorted, comparator);
NOT USED ANYMORE; it's here for helping people migrate from Wicket 1.2 to Wicket 1.3
"this method is not used any more (and shouldn't be called by clients anyway)");
- Parameters:
component
Component to remove from this container
Removes the given component
- Parameters:
id
The id of the component to remove
Removes all children from this container.
Note: implementation does not call for each
component.
private static final long serialVersionUID = 1L;
return "RemoveAllChange[component: " + getPath() + ", removed Children: " +
for (int i = 0; i < size; i++)
for (int i = 0; i < size; i++)
Renders the entire associated markup stream for a container such as a Border or Panel. Any
leading or trailing raw markup in the associated markup is skipped.
- Parameters:
openTagName
the tag to render the associated markup forexceptionMessage
message that will be used for exceptions
associatedMarkupStream.skipUntil(openTagName);
if (!((associatedMarkupOpenTag != null) && associatedMarkupOpenTag.isOpen() && (associatedMarkupOpenTag instanceof WicketTag)))
associatedMarkupStream.next();
Replaces a child component of this container with another
child.getId() + "', component=" + child));
child.markupIndex = replaced.markupIndex;
if (compModel == previous)
else if (compModel == model)
Get the number of children in this container.
- Returns:
- Number of children in this container
- Parameters:
detailed
True if a detailed string is desired- Returns:
- String representation of this container
buffer.append("[MarkupContainer "); buffer.append(", children = "); for (int i = 0; i < size; i++)
Traverses all child components of the given class in this container, calling the visitor's
visit method at each one.
- Parameters:
clazz
The class of child to visit, or null to visit all childrenvisitor
The visitor to call back to- Returns:
- The return value from a visitor which halted the traversal, or null if the entire
traversal occurred
Traverses all child components in this container, calling the visitor's visit method at each
one.
- Parameters:
visitor
The visitor to call back to- Returns:
- The return value from a visitor which halted the traversal, or null if the entire
traversal occurred
- Parameters:
component
Component being added
- Parameters:
child
Child to add
If the given object is a
MarkupContainer.ComponentSourceEntry instance and
reconstruct
is true, it reconstructs the component and returns it. Otherwise it just returns the object
passed as parameter
- Parameters:
objectreconstructparentindex- Returns:
component = postprocess(children[index], reconstruct, this, index);
if (children[index] != component)
children[index] = component;
for (int i = 0; i < size; i++)
if (children[i] != component)
for (int i = 0; i < size; i++)
final Object removed = c[index];
replaced = children[index];
Ensure that there is space in childForId map for a new entry before adding it.
- Parameters:
child
The child to put into the map- Returns:
- Any component that was replaced
- Parameters:
component
Component being removed
Renders the next element of markup in the given markup stream.
- Parameters:
markupStream
The markup stream
component.render(markupStream);
while (container != null)
if (resolver.resolve(this, markupStream, tag))
" but no <wicket:extend>");
"' in " + this + ". This means that you declared wicket:id=" + id +
" in your markup, but that you either did not add the " +
"component to your page at all, or that the hierarchy does not match.");
Get the markup stream for this component.
- Returns:
- The markup stream for this component, or if it doesn't have one, the markup stream
for the nearest parent which does have one
Handle the container's body. If your override of this method does not advance the markup
stream to the close tag for the openTag, a runtime exception will be thrown by the framework.
- Parameters:
markupStream
The markup streamopenTag
The open tag for the body
Renders this component. This implementation just calls renderComponent.
Renders this component and all sub-components using the given markup stream.
- Parameters:
markupStream
The markup stream
" failed to advance the markup stream");
Renders markup for the body of a ComponentTag from the current position in the given markup
stream. If the open tag passed in does not require a close tag, nothing happens. Markup is
rendered until the closing tag for openTag is reached.
- Parameters:
markupStream
The markup streamopenTag
The open tag
" failed to advance the markup stream");
Set markup stream for this container.
- Parameters:
markupStream
The markup stream
super(container, component, componentSource);
System.arraycopy(lst.childs, 0, tmp, 0, lst.size);
for (int i = 0; i < size; i++)
for (int i = 0; i < size; ++i)
for (int i = 0; i < children.length; i++)
- Returns:
- True if this markup container has associated markup
if (children instanceof Object[])
if (index > size || index < 0)
int numMoved = size - index - 1;
if (minCapacity > oldCapacity)
int newCapacity = oldCapacity * 2;
if (newCapacity < minCapacity)
newCapacity = minCapacity;