I’ve just tried out GWT’s editor framework and got it working for a small example. But I was wondering why sub-editors need to be package-private?
There is a comment in an example in the linked page that specifically mentions package-protected fields, but I cannot find the reason why.
// Sub-editors are retrieved from package-protected fields, usually initialized with UiBinder.
// Many Editors have no interesting logic in them
public class PersonEditor extends Dialog implements Editor<Person> {
Label nameEditor;
AddressEditor addressEditor;
...
}
In the example I tried myself, I only got it working if my sub-editors are package-private, if i make them private, the binding does no longer work.
Can anyone explain to me why this restriction exists? It makes my coding style appear a bit inconsistently. Thanks!
Similar to UiBinder, the generator for an
EditorDrivergenerates classes along-sideEditorclasses. These classes need access to the editors to be able to work with them.Put differently, the editor framework won’t modify you classes (there’s no magic), so you have to somehow expose your sub-editors: package-private is enough, but
publicwould of course work too.The best way to understand what’s going on is to pass the
-genoption (followed by a directory path) to the GWT compiler of dev mode, so that it outputs all the generated classes to disk. Be warned though: the editor framework is really hard to comprehend!Also, if your editor extends some other class in another package that contains a sub-editor (that you want to inherit), that subeditor must be visible from the package of the child class, so it has to be
publicin the parent class, or be explicitly exposed by the child class (using an accessor method that’s notprivate).