简体   繁体   中英

GWT MVP: pass data from view to presenter

I am looking at this GWT MVP tutorial:

http://www.gwtproject.org/articles/mvp-architecture.html#binding

The data is passed from the presenter to the view using this method:

display.setData(data);

where data is ArrayList<String>

How would I pass the data between view and presenter if I had something like a SelectBox in my view where I can select multiple values that I probably populate from a database?

I would store the SelectBox values probably in a HashMap.

Should I implement a second method to pass this to the presenter or should I try to keep the communication between view and presenter down to just one method?

In essence: How can views and presenters communicate through a simple method that ideally takes only one parameter, taking into consideration that sometimes I need to pass a simple string which represents an e-mail address and sometimes something more complex such as the values of a SelectBox?

You can add as many methods as you like to make your communication between your VIEWS & PRESENTERS! The key point lies in the choice of your methods and the implementation, because, debugging a GWT code-base is a nightmare!

There are approaches that you could choose from:

  1. You can have a DISPLAY interface of your PRESENTER be implemented on your VIEW
  2. You could generate an event (on MULTI-SELECT of Values from your SelectBox on VIEW), implement a corresponding handler on your PRESENTER to overcome multiple methods that need to be put in your DISPLAY interface!

Choose your option, based on your requirement and also on the complexity of it! My suggestion is to have an event, since the same piece of code can be reused somewhere else as well!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM