I would like to start a discussion on separating the pure model and the user interface model in Spring 3.
By a pure model, I mean the main object / objects that I retrieve from the database, say, some "user account". It contains enough information to display it as HTML or pass it to a web service.
By the UI model, I mean all the supporting materials that I need in the user interface to work with this object. For instance. if the "user account" has a "state", then I need to get all the "states" from the database, for example, in the combo box. The views are complex, and in some cases they require more information, in others less. It would also be nice to be able to modify some lists by adding elements such as "Select All", which is pure user interface material (and not very convenient from the viewing template).
I heard there the so-called Model-View-ViewModel template, which seems to solve these problems, but I have never tried implementing it.
The solution I'm using now is to break the logic into two services โ one for the clean model and one for the user interface model. It looks like this:
@RequestMapping(value="app/user_accounts/{id}") public String getUserAccount(@PathVariable("id") String id) { service.getUserAccount(id); // Gets main object and puts it into model presenter.formUserAccount(); // Gets all classifier for main object properties return "user_account"; }
What I don't like about this is that the view and its so-called presentation model are not tied to each other. I can call presenter.formUserAccount () and return an absolutely unrelated view name.
Another approach that I see is similar to Spring controller annotation. We have classes annotated as @ViewModels and methods that display for viewing names. The interceptor finds and executes these methods before displaying a specific view. They seem quite elegant, but require a lot of coding.
How would you solve this problem?
source share