Setting default values and readonly fields

Topics: Web Client Software Factory, UIP Application Block discussion, User Forum
Aug 14, 2007 at 8:32 AM
Hi all

If I understand mvp (model-view-presenter) framework correct, then neither the gui knows something about the presenter nor the presenter knows more about the gui than is specified in the Interface between theme, correct? Not the gui (or the corresponding code-behind class) gets the data but the data is delivered from the presenter to the gui. Only the presenter has knowledge about the deeper layers of the application an thus pushs the data to the gui, correct?

Under these circumstances im asking me what is a good aproach to implement the following two requirements:
- Default values (e.g. in a dropdownlist set a default language to german based on db-based data, if the user surfs from germany on my page)
- Enabled/Disabled controls (e.g. if the user comes from germany, so a dropdownlist 'state' is not required and can be disabled)

For both of these requirements either the code-behind class has to know about data or the presenter has to know what for controls are on the gui. But both of these seems for me to violate the idea of mvp, doesn't it? What is a good solution for this two requirements?

Thank you for your answer.
Best regards
Adrian
Aug 14, 2007 at 12:54 PM
I think that the presenter should only know the current language of the interface. you can override the OnViewInitialized() or OnViewLoaded methodes to passe the langage information to the presenter.
To enable/disable controls you can add some attributes in the view interface to control witch data are needed (ex: DisableState attribute).
Aug 17, 2007 at 3:05 PM

Default values (e.g. in a dropdownlist set a default language to german based on db-based data, if the user surfs from germany on my page)


Maybe a possible solution would be to:

  • have a service that retrieves the data from DB
  • make that presenter use that service in a method like retrieveDataList()
  • create a method in the view’s code behind called populateDropdownList() that would call _presenter.retrieveDataList()

This way the presenter just retrieves to its views the data list that has to be loaded, and the view makes use of that presenter’s method to get the data that has to be loaded in the dropdown list.


Enabled/Disabled controls (e.g. if the user comes from germany, so a dropdownlist 'state' is not required and can be disabled)


Here, maybe the presenter could have a shouldShowState method that the view could use in order to know whether to enable that control or not (by handling it in the view’s onLoad).

Besides this, from what you are describing maybe you will find of use these articles on globalization and localization:


Hope it helps!

Luciano G. Panaro
http://staff.southworks.net/lpanaro