Hybrid View

    Thank you for reporting this bug. We will make it our priority to review this report.
  1. #1
    Sencha User
    Join Date
    Oct 2011
    Posts
    54
    Vote Rating
    0
    DarekKay is on a distinguished road

      0  

    Question [CLOSED] Unable to add more than one widget to a ContentPanel?

    [CLOSED] Unable to add more than one widget to a ContentPanel?


    Feature or bug?

    Here's a very simple example code:
    Code:
    ContentPanel view = new ContentPanel();
    
    TextButton btn1 = new TextButton("1");
    TextButton btn2 = new TextButton("2");
    
    view.add(btn1);
    view.add(btn2);
    
    System.out.println("view.getWidgetCount() = " + view.getWidgetCount()); // = 1
    RootLayoutPanel.get().add(view);
    The problem is, only the last widget (btn2) is really rendered. getWidgetCount() returns 1, as if btn1 was never added.
    If it's a feature (like "you have to add another panel wrapping all buttons") - what would be getWidgetCount() for?

  2. #2
    Software Architect
    Join Date
    Sep 2007
    Posts
    13,971
    Vote Rating
    132
    sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light

      0  

    Default


    ContentPanel is a SimpleContainer and so only contains one child at a time. You need to wrap them in a VerticalLayoutContainer for example

  3. #3
    Sencha User
    Join Date
    Oct 2011
    Posts
    54
    Vote Rating
    0
    DarekKay is on a distinguished road

      0  

    Default


    Thank you, I didn't notice the new SimpleContainer concept. I guess, it should be fixed/improved though, since the SimpleContainer.add() method says:
    The expectation is that this method would be overridden by a child object.
    And that's what ContentPanel (and other SimpleContainer subclasses) don't do. And therefore it's not very intuitive, especially if you want to migrate your 2.x application, where you could use ContentPanel.add() to add more than one widget.

    Also, as mentioned, inherited methods like "getWidgetCount()" or "getWidget(int)" lead to even more confusion. Seeing this method on a SimpleContainer make a developer assume, it could actually contain more than one widget. Making those methods private, for example, would prevent such assumptions.

  4. #4
    Software Architect
    Join Date
    Sep 2007
    Posts
    13,971
    Vote Rating
    132
    sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light

      0  

    Default


    Theses methods are comming from a GWT interface.

    In GXT 3 the layouts are bound into the containers. We are still working on adding more javadocs, however there are currently no plans to change the design. Contentpanel does not have any insert method. SimplePanel from GWT behaves also exactly the same way, only that it will throw an exception.

    If you take a look at Widget.removeFromParent you will see that the HasWidget interface (that has the add method) is required).

    If you require to handle more than one widget, you need to add another container into the ContentPanel, like a FlowLayoutContainer.


    In GXT 2 the add method maybe always works. However when using a FitLayout only the first child would have been used, same in a CenterLayout. In GXT 3, the container takes care of all this.

Thread Participants: 1