简体   繁体   English

GWT MVP:将数据从视图传递到演示者

[英]GWT MVP: pass data from view to presenter

I am looking at this GWT MVP tutorial: 我正在看这个GWT MVP教程:

http://www.gwtproject.org/articles/mvp-architecture.html#binding 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> 其中数据是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? 如果我的视图中有类似SelectBox之类的东西,可以在其中选择可以从数据库填充的多个值,该如何在视图和演示者之间传递数据?

I would store the SelectBox values probably in a HashMap. 我可能会将SelectBox值存储在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? 本质上:考虑到有时我需要传递一个简单的字符串来表示电子邮件地址,有时又需要传递一些更复杂的信息(例如a的值),视图和演示者如何通过理想的方式仅采用一个参数来进行通信。 SelectBox?

You can add as many methods as you like to make your communication between your VIEWS & PRESENTERS! 您可以根据需要添加任意数量的方法,以在VIEWS和PRESENTERS之间进行通信! The key point lies in the choice of your methods and the implementation, because, debugging a GWT code-base is a nightmare! 关键在于选择方法和实现,因为调试GWT代码库是一场噩梦!

There are approaches that you could choose from: 您可以选择以下方法:

  1. You can have a DISPLAY interface of your PRESENTER be implemented on your VIEW 您可以在VIEW上实现PRESENTER的DISPLAY界面
  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! 您可以生成一个事件(在VIEW上的SelectBox中对值进行多重选择),在PRESENTER上实现相应的处理程序,以克服需要在DISPLAY接口中放置的多种方法!

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! 我的建议是要有一个事件,因为同一段代码也可以在其他地方重用!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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