Well, once a wrapped widget is detached from DOM (and
Window.detachNow() is called) it is semantically just a regular widget
(since isAttached() is false) so then you should be able to simply use
it like any "regular" widget (one you created using new ).
If you are not talking about doing something like
RootPanel.get(someId).add(myDetatchedWidget); or
somePanel.add(myDetachedWidget); then you are beginning to tread off
into the land of easily created memory leaks. If you are trying to
manually insert this widget into DOM somehow, then hookup the event
system you are forced to manage the life cycle of that widget
yourself, and you will then have to break the circular reference
between GWT and DOM yourself.
-jason
On Feb 11, 2009, at 4:14 AM, Nicolas Wetzel wrote:
> Thank you Jason for your usefull response
>
>
> I missed it and it helps us to find a better solution than override
> the gwt-user.jar but there is still something wrong.
> The wrap() method calls widget.onAttach(); so the wrapped widget is
> attached when created, we can't put it in the used hierarchie of
> Gwt widget components : ie you can't call
> myHTMLFragment.getChildren().add(w);
> because when the parent (myHTMLFragment) will be attached, the
> recursive call of the wrappedWidget.onAttach() will failed.
> We have to manage the wrapped widgets with our own hierarchy like
> this :
>
> @Override
> public void add(Widget w) {
> if (w.isAttached()) // wrapped widget
> register(w);
> else
> super.add(w);
> }
>
> public void register(Widget w) {
> getWrappedChildren().add(w);
>
> }
>
>
> @Override
> protected void doDetachChildren() {
> super.doDetachChildren();
> DeferredCommand.addCommand(new Command(){
> public void execute() {
> for (Widget widget : getWrappedChildren())
> if (widget.getParent() == null){// wrapped elements
> RootPanel.detachNow(widget);//wrapped widget are
> detached //
> }
>
> }});
>
>
> }
> it work fine but what happen's when you want to re-attache the
> HTMLFragment ? who can re-attach the wrapped widget ? (the
> onAttach() is protected)
> the only way we found is to put wrapped widgets in the gwt hierachie
> after the call of RootPanel.detachNow(widget);
> and that's not a very good solution!
> Nicolas
>
>
> On Tue, Feb 10, 2009 at 7:30 PM, Jason Essington <[email protected]
> > wrote:
> RootPanel.detachNow(Widget) method should be called before removing
> a wrapped widget from DOM to prevent your memory leak.
>
> I believe that this method is documented in every widget that
> implements .wrap()
>
> -jason
>
>
> On Feb 10, 2009, at 10:55 AM, Nicolas Wetzel wrote:
>
>> Hi all! ,
>>
>> The Widget.wrap() API is very usefull to build widgets(fragments)
>> from html templates retrieved from server or bound with the java
>> widget class at the compilation time (generators).
>> By this way, the design (HTML+CSS) is entirely delagated to Web
>> Developpers, Java Gwt Developpers have to manage only with GWT
>> Widget which are in fact only controllers:
>>
>> Each controler pick up some html element by id left in its
>> corresponding template and "build" gwt widget (TextBox,Label
>> etc...) with the wrap API to manage the (dynamic) behavior.
>> No css gwt api is used, no Panel for composition is used.
>>
>> Everything works fine while the widget fragment is attached to the
>> DOM (RootPanel) but there is a trouble :
>> If the widget fragment is detached its components (i e widgets
>> created with the wrap api) are not garbaged because they don't
>> have any parent.
>> So there is a memory leak. The wrap method doesn't alow to link
>> the life cycle of the component to its logical parent i e the
>> widget parent. Here is the code of the wrap method :
>>
>> public static Label wrap(Element element) {
>> // Assert that the element is attached.
>> assert Document.get().getBody().isOrHasChild(element);
>>
>> Label label = new Label(element);
>>
>> // Mark it attached and remember it for cleanup.
>> label.onAttach();
>> RootPanel.detachOnWindowClose(label);
>>
>> return label;
>> }
>>
>>
>> By the call of "RootPanel.detachOnWindowClose(label);" the widget
>> is gabaged only when the main window is closed. It is not very
>> clean if the fragment is garbaged. We reported this touble
>> http://code.google.com/p/google-web-toolkit/issues/detail?id=3113
>> in the bug tracker few months ago but it still in the same
>> state .
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>
>
>
>
>
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---