ComponentRenderer extends Renderer<SOURCE> { @Override public Rendering<SOURCE> render(Element container, DataKeyMapper<SOURCE> keyMapper, Element contentTemplate) { ComponentRendering rendering = new ComponentRendering( keyMapper == null ? null : keyMapper::key); rendering.setTemplateElement(contentTemplate); container.getNode() .runWhenAttached(ui -> setupTemplateWhenAttached( ui, container, rendering, keyMapper)); return rendering; } ComponentRenderer(SerializableSupplier<COMPONENT> componentSupplier,
            SerializableBiConsumer<COMPONENT, SOURCE> itemConsumer);  ComponentRenderer(
            SerializableSupplier<COMPONENT> componentSupplier);  ComponentRenderer(
            SerializableFunction<SOURCE, COMPONENT> componentFunction);  ComponentRenderer(
            SerializableFunction<SOURCE, COMPONENT> componentFunction,
            SerializableBiFunction<Component, SOURCE, Component> componentUpdateFunction); protected  ComponentRenderer(); @Override Rendering<SOURCE> render(Element container,
            DataKeyMapper<SOURCE> keyMapper, Element contentTemplate); void setComponentRendererTag(String componentRendererTag); COMPONENT createComponent(SOURCE item); Component updateComponent(Component currentComponent, SOURCE item);  }
@Test public void templateRenderered_parentAttachedBeforeChild() { UI ui = new TestUI(); TestUIInternals internals = (TestUIInternals) ui.getInternals(); ComponentRenderer<TestLabel, String> renderer = new ComponentRenderer<>( e -> (new TestLabel())); Element containerParent = new Element("div"); Element container = new Element("div"); KeyMapper<String> keyMapper = new KeyMapper<>(); ComponentDataGenerator<String> rendering = (ComponentDataGenerator<String>) renderer .render(container, keyMapper); containerParent.getNode().runWhenAttached( ui2 -> ui2.getInternals().getStateTree() .beforeClientResponse(containerParent.getNode(), context -> { Assert.assertNotNull( "NodeIdPropertyName should not be null", rendering.getNodeIdPropertyName()); JsonObject value = Json.createObject(); rendering.generateData("item", value); Assert.assertEquals( "generateData should add one element in the jsonobject", 1, value.keys().length); })); attachElement(ui, containerParent); attachElement(ui, container); internals.getStateTree().runExecutionsBeforeClientResponse(); }
@Test public void templateRenderered_childAttachedBeforeParent() { UI ui = new TestUI(); TestUIInternals internals = (TestUIInternals) ui.getInternals(); ComponentRenderer<TestLabel, String> renderer = new ComponentRenderer<>( e -> (new TestLabel())); Element containerParent = new Element("div"); Element container = new Element("div"); KeyMapper<String> keyMapper = new KeyMapper<>(); ComponentDataGenerator<String> rendering = (ComponentDataGenerator<String>) renderer .render(container, keyMapper); containerParent.getNode().runWhenAttached( ui2 -> ui2.getInternals().getStateTree() .beforeClientResponse(containerParent.getNode(), context -> { Assert.assertNotNull( "NodeIdPropertyName should not be null", rendering.getNodeIdPropertyName()); JsonObject value = Json.createObject(); rendering.generateData("item", value); Assert.assertEquals( "generateData should add one element in the jsonobject", 1, value.keys().length); })); attachElement(ui, container); attachElement(ui, containerParent); internals.getStateTree().runExecutionsBeforeClientResponse(); }