tags:

views:

2952

answers:

2

Howdy,

I'm learning GWT and have started to get the hang of it. I'm at the point where my code is getting to be a spaghetti mess so I'm going back and factoring reasonable bits of it out as Composites. The first problem I ran into was that my tool support failed to give the new Composite class an initWidget() method. It did include a default constructor.
For the time being, I've simply filled in my overridden initWidget() method with a call to super(initWidget(w)) My project compiles and runs as expected, though I feel as though I must be missing something.

What should I keep in mind when overriding init and what if anything do i need to place in the constructor. Is there anything else that I need to know or does it just boil down to regular old Java after this?

Clarification - It has occurred to me that there are probably different answers to this question depending on whether you intend to release said Composite classes as part of a library or simply part of your stand-alone app. I in particular have no intention at this time of developing externally useful components (mainly because I'm so green in this particular technology.)

Thanks!

A: 

"GWT Conference: Best Practices for Building Libraries" gives a couple of tips. You should also look at the source of GWT and at the source of one of the libraries for GWT (like gwt-ext)

[EDIT] I just saw another option: suco. From the description:

A micro library that helps to maintain your GWT client code clean and modular.

Aaron Digulla
yea me too, deleted old comment...
sweeney
+3  A: 

I'm not sure if I understand what you are trying to do. But for all the Composite's I've written I've never overridden the initWidget method. Because Composite itself doesn't need to be initialized with a constructor, i.e. no need to call super() my constructors of widgets extending composite look something like:

public mywidget() {
  SomePanel p = new SomePanel();
  ....
  initWidget(p);
}

As a best practice, imo, only the widget extending Composite should call it's 'own' initWidget.

Hilbrand
I think this is probably the answer to my whole set of problems surrounding custom widgets. I was also getting into a situation where the gui tools wouldnt render many of my custom widgets, most likely cuz neither my constructor nor init calls were correct. I'll check it out when i get home... thx
sweeney