List of usage examples for org.apache.wicket MarkupContainer getPath
public final String getPath()
From source file:com.francetelecom.clara.cloud.presentation.utils.PaasWicketTester.java
License:Apache License
public String lookupPath(final MarkupContainer markupContainer, final String path) { // try to look it up directly if (markupContainer.get(path) != null) return path; // if that fails, traverse the component hierarchy looking for it final List<Component> candidates = new ArrayList<Component>(); markupContainer.visitChildren(new IVisitor<Component, List<Component>>() { Set<Component> visited = new HashSet<Component>(); @Override/* w w w . j ava 2s . c o m*/ public void component(Component c, IVisit<List<Component>> visit) { if (!visited.contains(c)) { visited.add(c); if (c.getId().equals(path)) { candidates.add(c); } else { if (c.getPath().endsWith(path)) { candidates.add(c); } } } } }); // if its unambiguous, then return the full path if (candidates.isEmpty()) { fail("path: '" + path + "' not found for " + Classes.simpleName(markupContainer.getClass())); return null; } else if (candidates.size() == 1) { String pathToContainer = markupContainer.getPath(); String pathToComponent = candidates.get(0).getPath(); return pathToComponent.replaceFirst(pathToContainer + ":", ""); } else { String message = "path: '" + path + "' is ambiguous for " + Classes.simpleName(markupContainer.getClass()) + ". Possible candidates are: "; for (Component c : candidates) { message += "[" + c.getPath() + "]"; } fail(message); return null; } }