My favorites | Sign in
Project Home Downloads Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
BindingInitializer  
Mvp binding initializer
Updated Sep 4, 2010 by gal.dol...@gmail.com

Introduction

The initialize() method on AbstractPresenter and AbstractController was removed.

Now we can convert any zero-arguments method to an initializer with the annotation: @BindingInitializer. You can also use @ViewHandler's as initializers.

All @BindingInitializers will get called on every binder.bind() call.

Example

@RunAsync
@PlaceName("dynamic")
public class DynamicPresenter extends AbstractPresenter<DynamicPresenter, DynamicView, DynamicBinder> implements Place<Void> {

    public interface DynamicBinder extends ViewBinder<DynamicPresenter, DynamicView> {
    }

    protected final ArrayList<String> list = new ArrayList<String>();

    private final MainPresenter hasContent;
    
    @ViewField
    HasHTML table;

    @Inject
    public DynamicPresenter(MainPresenter hasContent) {
        this.hasContent = hasContent;
    }

    @Override
    public void go(Void data) {
        hasContent.setContent(view, 1);
    }

    @ViewHandler
    @BindingInitializer
    protected void reset$click() {
        list.clear();

        // Generate random data
        for (int n = 0; n < 10; n++) {
            String item = "Row " + n;
            list.add(item);
        }
        
        render();
    }

    ....
    ....
}

Testing

In your GuitTest's this will work as expected. Your Initializers will get called magically when you get a presenter.

Powered by Google Project Hosting