* @param rc the relevant <code>RenderContext</code>
* @param update the update
*/
private void renderAddChildren(RenderContext rc, ServerComponentUpdate update) {
Element domAddElement = DomUpdate.renderElementAdd(rc.getServerMessage());
Column column = (Column) update.getParent();
String elementId = ContainerInstance.getElementId(column);
Component[] components = update.getParent().getVisibleComponents();
Component[] addedChildren = update.getAddedChildren();
for (int componentIndex = components.length - 1; componentIndex >= 0; --componentIndex) {
boolean childFound = false;
for (int addedChildrenIndex = 0; !childFound && addedChildrenIndex < addedChildren.length; ++addedChildrenIndex) {
if (addedChildren[addedChildrenIndex] == components[componentIndex]) {
DocumentFragment htmlFragment = rc.getServerMessage().getDocument().createDocumentFragment();
renderChild(rc, update, htmlFragment, column, components[componentIndex]);
if (componentIndex == components.length - 1) {
DomUpdate.renderElementAddContent(rc.getServerMessage(), domAddElement, elementId, htmlFragment);
} else {
DomUpdate.renderElementAddContent(rc.getServerMessage(), domAddElement,elementId,
elementId + "_cell_" + ContainerInstance.getElementId(components[componentIndex + 1]),
htmlFragment);
}
childFound = true;
}
}
}
// Special case: Recall the child which was rendered at the last index of the column on the previous
// rendering. If this child is still present but is no longer at the last index, render a spacing
// cell beneath it (if necessary).
ColumnPeerRenderState renderState = (ColumnPeerRenderState) rc.getContainerInstance().getRenderState(column);
if (renderState != null && renderState.lastChild != null) {
int previousLastChildIndex = column.visibleIndexOf(renderState.lastChild);
if (previousLastChildIndex != -1 && previousLastChildIndex != column.getVisibleComponentCount() - 1) {
// At this point it is known that the child which was previously last is present, but is no longer last.
// In the event the child was removed and re-added, the special case is unnecessary.
boolean lastChildMoved = false;
for (int i = 0; i < addedChildren.length; ++i) {