Configure View

Bruce's Avatar


14 Feb, 2012 05:38 PM

I am new to RobotLegs (and MVC).

In the past (pre RobotLegs), I generally expose a dataProvider property on my "views" where the dataProvider is typically a complex object or collection. Inside the view, the dataProvider setter then goes about the business of binding the members of the object type of the dataProvider to the UI elements.

The framework documentation suggests that mediators "are used to handle framework interaction with View Components". It doesn't say anything about how the configuration of a view occurs.

So ... with RobotLegs, should the binding of data to UI elements be done in the mediator instead? In looking at the CafeTownsend example, that appears to be the case.

If I had a view with 3 DataGrids, multiple TextInput, etc, my mediator would set the dataProvider property of each DataGrid and the text property of each TextInput?

If I wanted to hide/show some of the DataGrids based on whether parts of my model were NULL, that would be done in the mediator also.

  1. Support Staff 1 Posted by creynders on 15 Feb, 2012 08:09 AM

    creynders's Avatar

    No, the binding of data to UI elements should definitely be done by the view, not the mediator. The idea is that you take your view, dump it in another project, satisfy it dependencies and it's fully functional again. In other words, the view should be as framework (and therefore mediator-) independent as possible. That gives you the maximum amount of flexibility and makes your view far more easily reusable.

    The mediator should simply act as a man-in-between, translating view-specific events to system-wide events and vice versa. The same applies to data. It should have as little as possible knowledge about the inner workings of the view.

    So, to take your example, the mediator should never set the dataprovider property of each datagrid directly, instead the view should expose getter/setters or methods through which the mediator can pass the data. If at a certain point in time you decide to use a different component instead of a datagrid and the mediator would be setting the dataprovider property of the datagrids directly, you'd have to not only modify your view but also your mediator. Encapsulation is again the main idea here.

  2. 2 Posted by Bruce on 15 Feb, 2012 04:31 PM

    Bruce's Avatar

    Right. That's typically how I have done it (non MVC) in the past. The view exposes getters & setters (although in my case, it often is a single setter called dataProvider).

  3. Ondina D.F. closed this discussion on 23 Feb, 2012 10:36 AM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac