Why doesn't HTMLPanel allow adding (widget)?

HTMLPanel inherits the add(Widget) method from com.google.gwt.user.client.ui.Panel , but does not override it. This throws an UnsupportedOperationException on call.

Were there any problems if it blocked it like a FlowPanel?

 @Override public void add(Widget w) { add(w, getElement()); } 

Background: HTMLPanel can be built faster than FlowPanel (innerHTML versus DOM manipulation). But after building it does not allow dynamically adding elements * .

* with the exception of the not very useful add(Widget widget, String id) method add(Widget widget, String id) , which makes it impossible to use the HTMLPanel twice in the document.

+4
source share
3 answers

This method was added to HTMLPanel in r9462 on December 17, 2010.

+1
source

I'm not sure that you should not include trivial overrides, but you can call add(Widget, Element) yourself if you want.

I think one of the ideas with HTMLPanel is that you can add a widget anywhere in the DOM panel, so it needs add () methods that force you to specify where to add the widget. This way you can build an HTMLPanel using some complex html, for example: "<div>...<div id="container"/>...<div>" , then call add(myWidget, "container") .

btw: add(Widget w, String id) is just a convience method. It does not create a new element with an identifier, but searches for an element with an identifier and calls add(Widget, Element) .

+3
source

As for the addition (widget widget, String id) - this method only works for elements defined in the HTMLPanel - as stated in javadoc (and I also checked this on my machine).

As I understand it, from javadoc addAndReplaceElement (widget widget, java.lang.String id) will work on any element, but still add a new widget to the HTMLPanel (basically the HTMLPanel will handle events, while the physical location of the widgets will be determined by remote item location).

0
source

Source: https://habr.com/ru/post/1313283/


All Articles