// Get the associated markup
IMarkupFragment markup = container.getAssociatedMarkup();
IMarkupFragment childMarkup = null;
// MarkupStream is good at searching markup
MarkupStream stream = new MarkupStream(markup);
while (stream.skipUntil(ComponentTag.class) && (childMarkup == null))
{
ComponentTag tag = stream.getTag();
if (TagUtils.isWicketHeadTag(tag))
{
if (tag.getMarkupClass() == null)
{
// find() can still fail an return null => continue the search
childMarkup = stream.getMarkupFragment().find(child.getId());
}
}
else if (TagUtils.isHeadTag(tag))
{
// find() can still fail an return null => continue the search
childMarkup = stream.getMarkupFragment().find(child.getId());
}
// Must be a direct child. We are not interested in grand children
if (tag.isOpen() && !tag.hasNoCloseTag())
{
stream.skipToMatchingCloseTag(tag);
}
stream.next();
}
return childMarkup;
}