Sunday, 11 August 2013

GWT: What is the best way to make custom ListBox

GWT: What is the best way to make custom ListBox

I have a question related to custom GWT widget.
I am going to make a custom ListBox which performs language selection. I
tried to achieve this by extending the GWT's ListBox class and it works.
public class LanguageListBox extends ListBox {
....
}
However, I think from a Java point of view, we might prefer composite over
inheritance. I do read some articles that suggests extending Composite
rather than the widget itself.
public class LanguageListBox extends Widget {
private final ListBox listBox;
LanguageListBox() {
listBox = new ListBox();
}
......
}
This class does not work. I believe I failed to create bridging method
that forward invocation to certain method of LanguageListBox to the
wrapped ListBox. However, I have checked there are numerous of methods of
ListBox, which method do I need to forward in order to make this design
working?
All in all, I am not sure what is the best design in this scenario.
Shall I make my LanguageListBox to extend ListBox directly or extend
Compisite and forward method invocation to the wrapped ListBox?
Are there any other better design for this?

No comments:

Post a Comment