/** * Looks up a component of the specified type by its name within the namespace occupied by this * component. * * @param <T> The expected return type. * @param name Component name or path. * @param type Expected return type. * @return The component sought, or null if not found. */ @SuppressWarnings("unchecked") public <T extends BaseComponent> T findByName(String name, Class<T> type) { return (T) findByName(name); }
/** * Returns a value for the named object. If the name is "self", the component itself is * returned. If the name is "parent" the component's parent is returned. Otherwise, name * resolution is attempted from several sources in the following order: * <ol> * <li>Tag library prefixes</li> * <li>The argument map passed to the materializer</li> * <li>The component's attribute map</li> * <li>The component's namespace</li> * <li>All ancestor attribute maps</li> * </ol> * * @param name The object name. * @return The value of the named object, or null if not found. */ public Object getValue(String name) { Object result = "self".equals(name) ? component : null; result = result != null ? result : "parent".equals(name) ? parent : null; result = result != null ? result : element.getTagLibrary(name); result = result != null ? result : args == null ? null : args.get(name); result = result != null ? result : component == null ? null : component.getAttribute(name); result = result != null ? result : parent == null ? null : parent.findByName(name); result = result != null ? result : parent == null ? null : parent.findAttribute(name); return result; } }
String name = i == -1 ? null : forward.substring(0, i); forward = forward.substring(i + 1); BaseComponent target = name == null ? this : findByName(name); ComponentException.assertTrue(target != null, this, "No component named \"%s\" found", name); ComponentException.assertTrue(!forward.isEmpty(), this, "No forward event specified");
: container.findByName(name);
BaseComponent component = root.findByName(name);
component = root == null ? null : root.findByName(target);
CompositePosition position = composite.getCompositePosition(); Assert.notNull(position, () -> "A snippet must specify a position"); BaseComponent anchor = anchorName == null ? this : findByName(anchorName); Assert.notNull(anchor, () -> "Could not locate any anchor named " + anchorName); BaseComponent parent = position == CompositePosition.FIRST || position == CompositePosition.LAST ? anchor
@Test public void testForm() throws Exception { BaseComponent root = PageUtil.createPage("web/org/carewebframework/ui/sharedforms/listviewForm.fsp", null).get(0); TestController controller = new TestController(); root.wireController(controller); ElementPlugin dummy = new ElementPlugin(); controller.onLoad(dummy); controller.requestData(); assertEquals(10, controller.model.size()); Grid grid = (Grid) root.findByName("grid"); Rows rows = grid.getRows(); assertEquals(10, rows.getChildCount()); assertEquals("Item #2.3", ((ILabeled) rows.getChildAt(1).getChildAt(2)).getLabel()); assertEquals("Test Title", controller.getCaption()); assertEquals("Header3", ((Column) grid.getColumns().getLastChild()).getLabel()); assertEquals(":1:false;0:33%;1:33%;2:33%", controller.getLayout()); controller.setLayout(":2:true;0:20%;1:30%;2:50%"); assertEquals(":2:true;0:20%;1:30%;2:50%", controller.getLayout()); } }