How to clear fields of editors?

307 views
Skip to first unread message

Drew Spencer

unread,
Nov 1, 2012, 11:35:34 AM11/1/12
to google-we...@googlegroups.com
Hi coders,

I have recently implemented some editors in my app, and am planning on using them for all editing of beans from now on. For each object (say Account, for example) I have an EditAccountPresenter, which can be used to a) create a new Account from scratch, or b) edit the details of an existing Account. Pretty standard stuff.

My question is this: As I have to wipe the fields when instantiating this new presenter, what is the best way to do this?

I have written a clear() method in each of my editors which wipes all fields and calls clear() on its parent as well, but I was surprised there is no built-in way to do this with the editor framework. Am I missing something?

Regards,

Drew

Drew Spencer

unread,
Nov 1, 2012, 12:32:57 PM11/1/12
to google-we...@googlegroups.com
Forgot to ask... is calling edit(new Account()) an acceptable way to do this?

Thanks

Jens

unread,
Nov 1, 2012, 1:10:58 PM11/1/12
to google-we...@googlegroups.com
When you want to edit a new instance (regardless if its an "empty" instance or not) you would create a new editor driver and call edit() with the new instance. As the editor graph represents more or less your object graph this should be enough to update the Ui. If the instance is "empty" the Ui should be "empty" as well after calling edit(). I guess thats why there is no clear() method.

-- J.

Thomas Broyer

unread,
Nov 1, 2012, 1:40:01 PM11/1/12
to google-we...@googlegroups.com

On Thursday, November 1, 2012 6:10:58 PM UTC+1, Jens wrote:
When you want to edit a new instance (regardless if its an "empty" instance or not) you would create a new editor driver and call edit() with the new instance. As the editor graph represents more or less your object graph this should be enough to update the Ui. If the instance is "empty" the Ui should be "empty" as well after calling edit(). I guess thats why there is no clear() method.

+1 except you don't have to create a new editor driver, you can reuse a previously built one.

If you want a clear(), then add a clear() to the edited object (Account) and edit() it again (or create a new object and edit() it, depending on your needs).

Jens

unread,
Nov 1, 2012, 2:45:29 PM11/1/12
to google-we...@googlegroups.com

+1 except you don't have to create a new editor driver, you can reuse a previously built one.

Wasn't there a memory leak somewhere in the editor framework when you reuse the driver? That was somewhere in my head while answering. But maybe its already solved.

-- J.

Thomas Broyer

unread,
Nov 1, 2012, 10:30:36 PM11/1/12
to google-we...@googlegroups.com

On Thursday, November 1, 2012 7:45:30 PM UTC+1, Jens wrote:

+1 except you don't have to create a new editor driver, you can reuse a previously built one.

Wasn't there a memory leak somewhere in the editor framework when you reuse the driver? That was somewhere in my head while answering. But maybe its already solved.

I'm not aware of anything like this (which doesn't mean there's no such issue, but it hasn't been reported)

Jens

unread,
Nov 2, 2012, 5:32:07 AM11/2/12
to google-we...@googlegroups.com
Just searched a bit and I think the post in question was https://groups.google.com/d/msg/google-web-toolkit/aemVcEjK_5I/7VISroJi2VcJ

But if its seems to be solved since GWT 2.3 it should be fine to reuse the editor driver.

-- J.

Drew Spencer

unread,
Nov 2, 2012, 6:25:05 AM11/2/12
to google-we...@googlegroups.com
Thanks guys! I think I will call edit() on a new instance, as this is a nice way of doing it.

Also, are there significant benefits to re-using an editor? Mine is declared as final at the top of my view, then in edit() I am calling driver.initialize() and then driver.edit(object). That means I'm re-using it, right?

Drew

Thomas Broyer

unread,
Nov 2, 2012, 7:31:35 AM11/2/12
to google-we...@googlegroups.com
Yes and no. You only need to call initialize() once.

Ümit Seren

unread,
Nov 2, 2012, 10:17:15 AM11/2/12
to google-we...@googlegroups.com

This is how I usually do it (not sure if this is the best approach).

In my View:

public class AccountDetailView  {

    public interface AccountDisplayDriver extends RequestFactoryEditorDriver<AccountProxy, AccountDisplayEditor> {}

    @UiField AccountDisplayEditor accountDisplayEditor;
    private final AccountDisplayDriver displayDriver;

    @Inject
    public AccountDetailView(final Binder binder, final AccountDisplayDriver displayDriver) {
        widget = binder.createAndBindUi(this);
        this.displayDriver = displayDriver;
        this.displayDriver.initialize(accountDisplayEditor);
    }

    @Override
     public AccountDisplayDriver getDisplayDriver() {
          return  displayDriver;
     }
}

GIN will make sure that GWT.create is called on the Driver interface and from my Presenter I can call getView().getDisplayDriver() to return the driver and interact with it.

Reply all
Reply to author
Forward
0 new messages