-
14 Dec 2011 7:04 AM #1
Unanswered: Inserting a component into an Div
Unanswered: Inserting a component into an Div
I am trying to create a div and insert a component into the div by as follows and have not been successful. What is it that I am doing incorrectly?
HorizontalPanel hp = new HorizontalPanel();
Html myHtml = new Html("<div id=\"htmlDiv\""></div>");
Label myLabel = new Label("Name");
hp.add(myHtml);
RootPanel.get("htmlDiv").add(myLabel);
-
14 Dec 2011 7:12 AM #2
That will only work, when the element with the id "htmlDiv" is already in the page.RootPanel.get("htmlDiv").add(myLabel);
-
14 Dec 2011 7:16 AM #3
Is there any other way to add the new Html element and to induce a component into it? Would forcing the hp.layout() help?
HorizontalPanel hp = new HorizontalPanel();hp.layout();
Html myHtml = new Html("<div id=\"htmlDiv\""></div>");
Label myLabel = new Label("Name");
hp.add(myHtml);
RootPanel.get("htmlDiv").add(myLabel);
Thanks,
Kaushik
-
14 Dec 2011 7:29 AM #4
Another solution would be to use HtmlContainer. However this depends on your exact requirements.
-
14 Dec 2011 8:10 AM #5
I tried to add the label to the div, after the page was rendered and still could not find the div on the page.
private HorizontalPanel getHP(){
HorizontalPanel hp = new HorizontalPanel();
Html myHtml = new Html("<div id=\"htmlDiv\""></div>");
hp.add(myHtml);@Override
return hp;
}
protected void afterRender() {
// TODO Auto-generated method stub
Label listLabel = new Label("Sort By:");
listLabel.setId("listLabelId");
if (RootPanel.get("leftDiv") != null){
RootPanel.get("leftDiv").add(listLabel);
} else {
Window.alert("Cannot find the div");
}
}
Is there anything else that I need to be looking into.
-
14 Dec 2011 8:14 AM #6
Can you please provide a fully working testcase implementing EntryPOint? From what are you overrding afterRender?


Reply With Quote