1. #1
    Ext GWT Premium Member
    Join Date
    Jul 2009
    Posts
    56
    Vote Rating
    0
    Answers
    1
    kaushikGXT is on a distinguished road

      0  

    Default 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);

  2. #2
    Software Architect
    Join Date
    Sep 2007
    Posts
    13,717
    Vote Rating
    107
    Answers
    60
    sven is just really nice sven is just really nice sven is just really nice sven is just really nice

      0  

    Default


    RootPanel.get("htmlDiv").add(myLabel);
    That will only work, when the element with the id "htmlDiv" is already in the page.

  3. #3
    Ext GWT Premium Member
    Join Date
    Jul 2009
    Posts
    56
    Vote Rating
    0
    Answers
    1
    kaushikGXT is on a distinguished road

      0  

    Default


    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();
    Html myHtml = new Html("<div id=\"htmlDiv\""></div>");
    Label myLabel = new Label("Name");

    hp.add(myHtml);
    hp.layout();
    RootPanel.get("htmlDiv").add(myLabel);

    Thanks,
    Kaushik

  4. #4
    Software Architect
    Join Date
    Sep 2007
    Posts
    13,717
    Vote Rating
    107
    Answers
    60
    sven is just really nice sven is just really nice sven is just really nice sven is just really nice

      0  

    Default


    Another solution would be to use HtmlContainer. However this depends on your exact requirements.

  5. #5
    Ext GWT Premium Member
    Join Date
    Jul 2009
    Posts
    56
    Vote Rating
    0
    Answers
    1
    kaushikGXT is on a distinguished road

      0  

    Default


    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);
    return hp;
    }
    @Override
    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.

  6. #6
    Software Architect
    Join Date
    Sep 2007
    Posts
    13,717
    Vote Rating
    107
    Answers
    60
    sven is just really nice sven is just really nice sven is just really nice sven is just really nice

      0  

    Default


    Can you please provide a fully working testcase implementing EntryPOint? From what are you overrding afterRender?