Nested Editor creation question

27 views
Skip to first unread message

opn

unread,
Oct 25, 2011, 12:20:29 PM10/25/11
to google-we...@googlegroups.com
Hello,
I have a simple case where I've got an UserEditor and an AddressEditor inside the UserEditor. Then there's the UserEditorWidget (in DynatableRF it would be called UserEditorWorkflow, i think) which owns the UserEditor and starts the edit process, flushes the context etc.

Now I wondered why i have to use

@UiField(provided = true)
UserEditor userEditor

in my UserEditorWidget, while I can do

@UiField
UserAddressEditor userAddress;

in my UserEditor.

To make it clear: I have to instantiate the UserEditor myself (via new UserEditor( ) or injection) while UiBinder is able to create the "child editor" of the UserEditor itself.
Why is that?

Regards
Alex

Aidan O'Kelly

unread,
Oct 25, 2011, 1:40:17 PM10/25/11
to google-we...@googlegroups.com
On Tue, Oct 25, 2011 at 5:20 PM, opn <ope...@gmx.net> wrote:
Hello,


To make it clear: I have to instantiate the UserEditor myself (via new UserEditor( ) or injection) while UiBinder is able to create the "child editor" of the UserEditor itself.
Why is that?


If you can create your UserEditor, with 'new UserEditor() ' you don't need to use the 'provided=true'. UiBinder can create it for you. 
provided=true is for when UiBinder cannot create an instance of the object itself, either because it needs constructor arguments, or you want it to use a specific instance.

Cristian Rinaldi

unread,
Oct 25, 2011, 2:12:55 PM10/25/11
to google-we...@googlegroups.com
Hello:

Suppose you have a UserView interface, then you can use the interface instead of the concrete class.

class UserEditor ... {

......
......
UiField (provided = true)
UserView view

....
....

  @ Inject 
  UserEditor (UserView v) {
    this.view = v;

    UiBinder initialization ....
  }
}


where:

  class UserViewImpl implements UserView {
     ....
     ....
  }

By example with GIN:
   bind(UserView.class).to(UserViewImpl.class).in(Singleton.class);

Now, as says Aidan, if you not use GIN or other IOC, (provided = true) it is not necessary, UiBinder does it for you.

opn

unread,
Oct 26, 2011, 6:31:55 AM10/26/11
to google-we...@googlegroups.com
Thanks for your answers!

I found my mistake.

My

initWidget(uiBinder.createAndBindUi(this));

came too late in the constructor, after

editorDriver = GWT.create(Driver.class);
editorDriver.initialize(requestFactory, userEditor);

The editor was not initialized at that point and so i got the error.
Stupid mistake. Now works without provided=true (I initialized the self provided editor earlier, so the error didnt occur then).


Reply all
Reply to author
Forward
0 new messages