/** * Attaches a controller to the specified component and registers any recognized listeners to * the plugin. * * @param comp Target component. * @param controller Controller to attach. */ public void attachController(BaseComponent comp, IAutoWired controller) { plugin.tryRegisterListener(controller, true); comp.wireController(controller); }
/** * Wires a controller's annotated components and event handlers, in that order, using this * component to resolve name references. * * @param controller The controller to wire. The following values are recognized: * <ul> * <li>self - Controller is the component itself.</li> * <li><String> - Name of the class from which a controller instance will be * created.</li> * <li><Class> - The class from which a controller instance will be * created.</li> * <li><Collection> - Each element of the collection will be wired.</li> * <li>All other - The controller instance to be wired.</li> * </ul> */ @PropertySetter(value = "controller", bindable = false, defer = true, description = "Controller to be wired to this component.") public void wireController(Object controller) { wireController("", controller); }
wireController(mode, ctlr);
/** * Initializes a plugin, if not already done. This loads the plugin's principal cwf page, * attaches any event listeners, and sends a load event to subscribers. */ public void load() { PluginDefinition definition = getDefinition(); if (!initialized && definition != null) { BaseComponent top; try { initialized = true; top = container.getFirstChild(); if (top == null) { top = PageUtil.createPage(definition.getUrl(), container).get(0); } } catch (Throwable e) { container.destroyChildren(); throw createChainedException("Initialize", e, null); } if (pluginControllers != null) { for (Object controller : pluginControllers) { top.wireController(controller); } } findListeners(container); executeAction(PluginAction.LOAD, true); } }
@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()); } }