diff --git a/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java b/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java index 14a7c31ff2e..41a2a632032 100644 --- a/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java +++ b/wicket-core/src/main/java/org/apache/wicket/MarkupContainer.java @@ -235,9 +235,7 @@ else if (getParent() instanceof AbstractRepeater) } // the current markup tag - tag = (ComponentTag)markup.get(); - - + tag = markup.getTag(); if (tag.isClose()) { if (stack.isEmpty()) @@ -258,15 +256,19 @@ else if (getParent() instanceof AbstractRepeater) Component child = parent.get(tag.getId()); if (child == null) { - // try to deque a child component if one has not been found + child = findComponentByMarkup(tag); + } + if (child == null) + { + // try to deque a child component if one has not been found for (int j = stack.size() - 1; j >= 0; j--) { // we try to find a queued component from the deepest nested parent all the way // to the owner of the markup ComponentAndTag cat = stack.get(j); - ArrayList queue = cat.component.getMetaData(QUEUE); + List queue = cat.component.getMetaData(QUEUE); if (queue == null) { continue; @@ -280,6 +282,7 @@ else if (getParent() instanceof AbstractRepeater) break; } } + if (child != null) { queue.remove(child); @@ -291,12 +294,12 @@ else if (getParent() instanceof AbstractRepeater) if (child == null) { // if we didnt find a queued child we could use try the resolvers - child = ComponentResolvers.resolve(parent, markup, tag, null); if (child != null) { - tag.setId(child.getId()); - tag.setModified(true); + child.setMarkup(markup.getMarkupFragment()); +// child.setAuto(true); +// tag.setModified(true); } } @@ -308,12 +311,12 @@ else if (getParent() instanceof AbstractRepeater) // that will leave components in the queue and ondetach() will bomb } - if (child != null && child.isAuto()) - { - // TODO this is yet another hack, need to figure out how auto components fit into - // this and why they dont get correctly resolved second time around - child.setAuto(false); - } +// if (child != null && child.isAuto()) +// { +// // TODO this is yet another hack, need to figure out how auto components fit into +// // this and why they dont get correctly resolved second time around +// child.setAuto(false); +// } if (child == null) { @@ -363,6 +366,22 @@ else if (child instanceof MarkupContainer) } } + private Component findComponentByMarkup(final ComponentTag tag) + { + for (Component comp : this) + { + IMarkupFragment markup2 = comp.getMarkup(); + + // By purpose compare the object ids + if ((markup2 != null) && (markup2.get(0) == tag)) + { + return comp; + } + } + + return null; + } + private void lateAdd(MarkupContainer parent, Component queued) { parent.add(queued); @@ -530,36 +549,36 @@ public MarkupContainer addOrReplace(final Component... childs) * stream to be used to render the component. * @return True, if component has been added */ - public final boolean autoAdd(final Component component, MarkupStream markupStream) - { - if (component == null) - { - throw new IllegalArgumentException("argument component may not be null"); - } - - // Replace strategy - component.setAuto(true); - - if (markupStream != null) - { - component.setMarkup(markupStream.getMarkupFragment()); - } - - // Add the child to the parent. - - // Arguably child.setParent() can be used as well. It connects the child to the parent and - // that's all what most auto-components need. Unfortunately child.onDetach() will not / can - // not be invoked, since the parent doesn't known its one of his children. Hence we need to - // properly add it. - int index = children_indexOf(component); - if (index >= 0) - { - children_remove(index); - } - add(component); - - return true; - } +// public final boolean autoAdd(final Component component, MarkupStream markupStream) +// { +// if (component == null) +// { +// throw new IllegalArgumentException("argument component may not be null"); +// } +// +// // Replace strategy +// component.setAuto(true); +// +// if (markupStream != null) +// { +// component.setMarkup(markupStream.getMarkupFragment()); +// } +// +// // Add the child to the parent. +// +// // Arguably child.setParent() can be used as well. It connects the child to the parent and +// // that's all what most auto-components need. Unfortunately child.onDetach() will not / can +// // not be invoked, since the parent doesn't known its one of his children. Hence we need to +// // properly add it. +// int index = children_indexOf(component); +// if (index >= 0) +// { +// children_remove(index); +// } +// add(component); +// +// return true; +// } /** * @param component @@ -1687,16 +1706,21 @@ protected final boolean renderNext(final MarkupStream markupStream) Component component = get(id); if (component == null) { - component = ComponentResolvers.resolve(this, markupStream, tag, null); - if ((component != null) && (component.getParent() == null)) - { - autoAdd(component, markupStream); - } - else if (component != null) - { - component.setMarkup(markupStream.getMarkupFragment()); - } - } + component = findComponentByMarkup(tag); + } +// if (component == null) +// { +// component = ComponentResolvers.resolve(this, markupStream, tag, null); +// if ((component != null) && (component.getParent() == null)) +// { +// throw new WicketRuntimeException("Still need autoAdd(): " + tag.toString()); +// // autoAdd(component, markupStream); +// } +// else if (component != null) +// { +// component.setMarkup(markupStream.getMarkupFragment()); +// } +// } // Failed to find it? if (component != null) diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/html/internal/HtmlHeaderContainer.java b/wicket-core/src/main/java/org/apache/wicket/markup/html/internal/HtmlHeaderContainer.java index ffab069bbc3..14edddd0090 100644 --- a/wicket-core/src/main/java/org/apache/wicket/markup/html/internal/HtmlHeaderContainer.java +++ b/wicket-core/src/main/java/org/apache/wicket/markup/html/internal/HtmlHeaderContainer.java @@ -299,8 +299,14 @@ public IMarkupFragment getMarkup() "Bug: The Wicket internal instance of HtmlHeaderContainer is not connected to a parent"); } + IMarkupFragment markup = super.getMarkup(); + if (markup != null) + { + return markup; + } + // Get the page markup - IMarkupFragment markup = getPage().getMarkup(); + markup = getPage().getMarkup(); if (markup == null) { throw new MarkupException("Unable to get page markup: " + getPage().toString());