Understand MVC Pattern - model-view-controller

Recently I was asked what is the relationship between the Model/Controller/View in MVC pattern by my colleague. But unfortunately I think I didn't give a good explanation to him. So I search it in the google . and found most of diagrams put like this below.
Actually some parts of them I am not sure if I understand well. Please help to review it.
Controller is responsible for updating the Model.(Controller->Model)
Model can apply the change to the View when it is changed. and view can apply the change to the Model if the binding value from the Model is changed in the view.(Model<->View)
The view can accept the user actions so that sumbit all the UI inputs to Controller.(View->Controller)
The controller would determine the which view can be display based on the User Actions.(Controller->View)
Thanks.

Related

Odoo v12 finding view ID

Im trying to find view ID to edit it. I know about developer options, but in this case it is not working...
Odoo v12 community version. Trying to edit a view adding a new customer, when adding a followers into task in project module.
Tried to find it in technical -> views but without success
More details - short video showing my problem.
https://www.youtube.com/watch?v=q-oO7upPvto&feature=youtu.be
Beforehand: it is the view base.view_partner_simple_form.
How to find out? Yes, Odoo's debug mode is not helping that much here. But you can use it to find out what model is behind a field where you used "Create and Edit" context menu. In this case it's the model res.partner.
And from there you have to do a detective's work, or a bit like that. Just switch to the views list in technical and search for form views for model res.partner without a parent (base views not inheriting from other views). You will find 5-6 views and have to look into them one by one to find the right one.
For this case that is pretty simple, because there is only one view for res.partner model with so less fields in it.

How to create a side bar like twitter for OSX ? Suggestions about development choices

I'm curious to know how to create the sidebar used in twitter and many other Apps
What i'm asking for is not about graphics, but i'd like to know which is the better way to create a structure to permit switching between different sections.
I don't like asking for help without start by an opinion, thus, this is mine:
Generic view structure would be created with a NSSplitView
I Need a generic Model class managing sections and taking a pointer to the current one.
Here i'd add informations about image used for any section etc... (something like a custom UITabBarController for iOS.
The Left view of the split View would be connected to the generic Model and would be able to present its section and get the current one. Pushing a button will ask the generic Model to change the current section and load content in the Right view (some doubts about this use a Model that way :P probably not the better one)
The Right view loads other view controller as requested by left View (i have may doubts about how do that!)
I'm on the right way ? how would you build a structure like that of Twitter ?
(Off topic: I'd really appreciate correction of my terrible English to keep this question suitable for all users)
Here's what you need https://github.com/erndev/EDSidebar
That's pretty much how I would do it although what you call a "generic model" object, I would call a controller (because it fits in the controller part of MVC).
The right view would be a Tab View with the style set to "tabless" so you don't get the selection buttons at the top and the individual views within the tab view would be selected by the controller using -selectTabViewItemWithIdentifier:
That's how I would do it anyway.

ASP.NET MVC 3: get all textbox data from a view

I'm trying to get all the data that is submitted into textboxes at a view back to a controller so i can save the data to the database.
Some background information:
Teacher Task Quotation setup
The first view that the teacher sees are all the tasks he has given (dropdown). He can chose one of those tasks and click submit then he gets a view back where he can quote the students that submitted there tasks before the deadline.
So for each student he can change the points if he made a mistake or quote the task.
After that is done there are some points that need to be submitted. What i want to know is how i get all those points back (that are in the textboxes) from the form so i can easily submit them to the DB.
Edit:
It seems that my question is kinda hard to understand so i made a little sketch of the current situation and the problem - you can view it here - http://i43.tinypic.com/xap54m.jpg
Possible problems: i allready use a viewmodel to require the submission of a task.
Is it possible to have to viewmodels in a view?
This is a really basic MVC question. You should probably read the MVC music store tutorial/pdf or the Nerd Dinner tutorial as both will show how to save/insert to the database using Entity framework.
I'llpost some code a little later.
Use another viewmodel. To use two viewmodels in one view, either bind them together in a model class or use a tuple in a view like this:
#model Tuple<model1, model2>
Then you access it like this.
Model.Item1.Something and Model.Item2.Something

Is the GEF really a MVC framework?

in the tutorials from http://www.vainolo.com/tutorials/ the position of the model is saved in the model. I want to save all data to file and want to get the same view, when I load the file.
Searching for an answer for this question, I got another more important question:
Is the GEF really a MVC framework?
GEF Controllers tells the mvc controller role is taken from the EditPart. It creates the specified objects.
Regarding the examples the controller holds view parts, but the mvc pattern tells, that the controller only reacts on user interaction and tells the view, it has to update or what ever.
Concluding on it the following code is wrong, because it is part of EditPart and it changes:
public void refreshVisuals(){
IPersonFigure figure = (IPersonFigure)getFigure();
Person model = (Person)getModel();
figure.setName(model.getName());
figure.setSurname(model.getSurname());
}
Regarding wikipedia the view has an observer on the model, so the following sentence from GEF is wrong, isn't it?
The EditPart syncs the actual model state to the view and implements the observer.
In the MVC pattern, the controllers must listen to the changes of the model. In GEF, EditParts are the controllers so they must listen to their model to update the view according to the new state of the model.
So what is correct?
To prevent cross-posting have a look on http://www.eclipse.org/forums/index.php/m/755178/.
The wikipedia states a the start of the article on MVC that " MVC comes in different flavors (MVC overview). Sometimes the view can read the model directly and update itself, sometimes this is done by the controller.
The primary concept that MVC provides is decoupling the presentation from the view, which should contain no logic. Changes to the model are executed by the controllers, and changes to the view are caused when the model is changed. But this does not mean that the controller can't be the one who updates the view when the model changes. Someone has to do it, right? I personally think that having the view directly read from the model is not a good practice since it makes them too dependent, and that model and view should be completely separated. This is great when you have to make changes in your model (for example a field is changed from being real to being calculated) - you don't have to change your view (but you may have to change your controller, but this is normally easier).
Hope this clears things up for you.

MVC 3 - using reflection to choose a partial view - abuse?

I think I'm finally starting to get MVC 3, but if someone can validate this approach I'd feel better about it.
I have a website, let's say, and I have models for NormalPage and EventPage. EventPage has an EventDate, but that's the only difference, and let's just say that EventPage inherits from NormalPage if that makes life easier.
Two views handle these two (slightly) different models, one just showing the page, and the other displaying the date and showing a registration form. They have different designs, so different views are in order.
All the tutorials will say "yup, now write two Controllers: Events and Pages". That seems silly - both are just passing the model to a (appropriate) view. I can use a single "Page" controller and choose the appropriate view using reflection, right? typeof(Model), once I've pulled the data from the database, can tell me whether or not I should pull the Event view or the Page view.
Is that dumb, or asking for trouble, or misusing the framework? Thanks.
What do you intend to do with reflection? You don't need to do anything like that to return views dynamically. From any controller action, you can return View("EventView", eventModel) or View("NormalView", normalModel) and it will return that view.
On a different note, I'm not sure what tutorials suggested that it's typical to have one view per controller but it's not. It's typical to have several views and actions in one controller.

Resources