use of org.apache.wicket.markup.html.form.AutoLabelResolver.AutoLabel in project wicket by apache.
the class AutoLabelTextResolver method resolve.
@Override
public Component resolve(MarkupContainer container, MarkupStream markupStream, ComponentTag tag) {
if (tag instanceof WicketTag && "label".equals(tag.getName())) {
// We need to find a FormComponent...
Component related = null;
// ...which could be explicitly specified...
String forAttributeValue = tag.getAttribute("for");
if (forAttributeValue != null) {
Component component = AutoLabelResolver.findRelatedComponent(container, forAttributeValue);
related = component;
}
if (related == null) {
// ...or available through an AutoLabel, either directly above us...
if (container instanceof AutoLabel) {
related = ((AutoLabel) container).getRelatedComponent();
}
if (related == null) {
// ...or perhaps further up...
AutoLabel autoLabel = container.findParent(AutoLabel.class);
if (autoLabel != null) {
related = autoLabel.getRelatedComponent();
}
}
}
if (related == null) {
// ...or it might just not be available.
String forAttr = forAttributeValue != null ? " for=\"" + forAttributeValue + "\"" : "";
throw new ComponentNotFoundException("no related component found for <wicket:label" + forAttr + ">");
} else {
// ...found the form component, so we can return our label.
return new TextLabel(tag.getId(), related);
}
}
return null;
}
Aggregations