use of org.apache.wicket.core.request.handler.ComponentNotFoundException in project wicket by apache.
the class AutoLabelResolver method resolve.
@Override
public Component resolve(final MarkupContainer container, final MarkupStream markupStream, final ComponentTag tag) {
if (!tag.getId().startsWith(LABEL_ATTR)) {
return null;
}
final String id = tag.getAttribute(getWicketNamespace(markupStream) + WICKET_FOR).trim();
Component component = findRelatedComponent(container, id);
if (component == null) {
throw new ComponentNotFoundException("Could not find form component with id '" + id + "' while trying to resolve wicket:for attribute");
}
if (!(component instanceof ILabelProvider)) {
throw new WicketRuntimeException("Component pointed to by wicket:for attribute '" + id + "' does not implement " + ILabelProvider.class.getName());
}
if (!component.getOutputMarkupId()) {
component.setOutputMarkupId(true);
if (component.hasBeenRendered()) {
logger.warn("Component: {} is referenced via a wicket:for attribute but does not have its outputMarkupId property set to true", component.toString(false));
}
}
if (component instanceof FormComponent) {
component.setMetaData(MARKER_KEY, new AutoLabelMarker((FormComponent<?>) component));
}
return new AutoLabel(tag.getId(), component);
}
use of org.apache.wicket.core.request.handler.ComponentNotFoundException 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