Cannot add components to UI

Hi,

I implemented a PolymerTemplate as the RouteLayout. In the implementation, I would like to add a custom component to the body, which is UI. The code is “UI.getCurrent().getElement.inertChild(0, component);”. However, that custom component was not inserted under body in the end. Any advice of how to correct that?

Best regards,
Joey

Do you have a example of your code ?

Maybe if you have a Polymer element you have to access to the shadow root to add your component to.

Something like :

UI.getCurrent().getElement().getShadowRoot().ifPresent(s -> s.appendChild(component));

Here are my sample codes:

@Tag("logon-layout")
@HtmlImport(".....")
public class LogonLayout extends PolymerTemplate<TemplateModel> implement RouteLayout {

	public LogonLayout {
		UI.getCurrent().getElement.inertChild(0, new Html("<div>.....</div>"));
		.....
	}
}

After starting up, I found that the dom element for that Html didn’t get deployed, while others in polymertemplate did get deployed well. I also tried your suggestion to insertChild, but it failed as well. Instead, I used modifyBootstrapPage of BootstrapListener to insert node, and it worked.

Best regards,
Joey