Project

General

Profile

Processing on widget removal

Added by Thim Anneessens almost 13 years ago

Hello

I have made a JWt Widget that encapsulate a JQuery Widget. Seeing that JWt sites are statefull I need to do some extra js work when the widget is removed from the hierarchy in order to properly remove the widget (If not done there will be some artifacts due to the use of overlays by the JQuery Widget).

What is the better way to do it. For now I have found none that would not violate the basic OO principle of encapsulation.

NOTE: finalize() is not an option as it is called on garbage collection and not on removal from widget hierchy.

Thanks in advance for your help.

Thim.


Replies (5)

RE: Processing on widget removal - Added by Pieter Libin almost 13 years ago

Dear Thim,

You can put this JavaScript clean code in your remove() method which should override WWidget#remove().

You will need to explicitly call remove() on your widgets when you want to remove them from the server DOM hierarchy.

greetings,

Pieter

RE: Processing on widget removal - Added by Thim Anneessens almost 13 years ago

Hmmm, I thought of that but frankly it has multiple issues. Most of the time you will remove your widget indirectly (by removing parent widgets in the hierarchy). I this case remove() will not be called (from what I understand), resulting in unexpected behavior.

So using remove() will probably make the developers pull there hair when they do not understand the behavior and curse when they understand that they need to make their own algorithms to properly remove the widget when it is embedded deep inside the widget hierarchy.

Should a make a feature request or am I still missing something?

Thanks for the response,

Thim.

RE: Processing on widget removal - Added by Pieter Libin almost 13 years ago

Hi Thim,

when calling remove on widget, all remove is also called on all it's children.

Is this not the case when you try this?

greetings,

Pieter

RE: Processing on widget removal - Added by Thim Anneessens almost 13 years ago

Yes this work around would work. But its probably one of the worst way to do it.

- It is clearly not OO

- Will cause long term maintenance issues

- Is non intuitive

  • The constraint will have to implemented in all classes that will use the widget.

The worst is that my problem will be a frequent one because JWt makes stateful pages and most Javascript Widgets libraries are made for stateless pages. A lot of them are therefore badly tested for widget removal or do not offer any support for this feature.

Seeing that stateless is still the most popular way to make web pages, we cannot expect JS libraries to correct this in any foreseeable future. JWt should therefore offer the possibility to handle those cases in a proper fashion.

Doing so would make encapsulation of existing JS widgets easier and would allow developers to make better widgets.

Best regards,

Thim

RE: Processing on widget removal - Added by Koen Deforche over 12 years ago

Hey Thim,

The remove() method really is the good option. The problem is currently that remove() is not guaranteed to be called, e.g. when the entire session is invalidated.

What problems are you seeing with JavaScript widget libraries? We have some experience integrating several JavaScript widgets and widget removal is not a problem we notice (creation on the other hand, and dynamic loading, is more of a concern).

We will be fixing the session invalidation in the next release.

Regards,

koen

    (1-5/5)