12 Mar 2009 7:13 PM #1
Model Loading & Management Questions
Model Loading & Management Questions
While I have some experience with MVC frameworks before I would hardly consider myself an expert and am not too comfortable with that portion yet. I have a bunch of questions, and I'm not sure how clear they are or if they will seem like there coming out of left field, so I included by current level of understanding, of how I think the world works. We are currently backed by a custom API that is procedural based, and doesn't seem to transfer easiely to the model view (see below for a description of it).
1) While the servlet may retrieve objects lazily am I expected to render full views of the model to GWT, in otherwords, when I get a list of AuthorsByName, should I retrieve all there friends, and there books, recursively, to present a complete model to the UI.
2) What benefit is form bindings, currently when we load data we simply loop through all the form fields, that are named consistently with the model, and get the value and set the form. Then when we submit we take a new model, loop through all the form fields, and submit. The examples of Form Binding seem both useful and problematic, in that it seems good that everything that references a model is updated when it is (as it saves having to manage that when loading), but it seems like it will hammer our server if every field that the user updates in a form triggers an update request.
3) How should models be initialized constructed, I'm not sure if it's a good idea to pass around something like:
Author a = new Author();
I get the feeling that there should only ever be one instance of a model for a specific entity at one time.
4) Related to 3, should I be putting Data Loaders / Lookup functions in the model itself, so that it can lazily render itself as needed, then notify changes?
5) How should changes to the model be sent back to the servlet and managed?
6) How can we cache and minimize requests to the server as much as possible, we have a custom API backing our EXT GWT App, but it's fairly slow, and it seems to be that if I update an Object, everything referencing it should no right away.
---- How I view the Model world ---
This metaphor might be a bit forced, but instead of creating 4 different models, I think one model with some suspension of belief might be easier to deal with.
int uid; //Unique ID
String name; //Friendly name for users
List<Author> friends; //A list of an authors friends
String book_title; //A title of there book.
String book; //A very LONG string representing there entire book.
Our backend communicates with our data store via a custom API that is not model based, but we can construct some of the model using various calls.
The calls to our custom API have been simplified, but are impossible to change, they return various amounts of information.
Author LookupAuthor(uid); //Returns everything in the class, except the list of friends
Author LookupAuthor(name, book); //Same as above.
List<Author> getAuthorsFriends(uid); //Returns a list of authors that includes only there uid, name, book_title.
List<Author> getAuthorsByName(name); //Returns classes containing uid, name, book_title.
//Ignoring the update methods for now
In our prototype we did it this way:
We have a class called DataAccess that has these methods
Author getAuthor(name, book)
When a call was made to these, they would return an empty model, then fire a GWT RPC call, when that returned, they each fired there own unique event containing the parameters of the request, and anything listening would be notified that it was updated, and could reload the data. So one Controller/View AuthorView would have a form that called getAuthor(uid), it would get an empty model. Then the controller would listen for updateAuthor event, and then when that came, would call getAuthor(uid) again, so that it had an updated version. While in theory there is only one instance of a given entity in a model, at a time, this changes.
I've looked at some of the examples and the documentation, and it seems that this might be the wrong approach. The Reference guide mentions that models might be lazily rendered like ours, and I looked at the MailApp example, but turns out it loads the message body all in one shot.
The DataLoaders also seem confusing too me and I haven't been able to make heads or tails out of them, or how they can help. Caching / Preventing a bajillion requests seems to be problematic and confusing.