Introduction
NavWin Web MVP is a generic MVP (Model-View-Presenter) framework
written in C# which specifically implements a popular JavaScript AJAX library
(Google Web Toolkit) for the client side view. The original implementation used
the Dojo JavaScript library, however the Google Web Toolkit uniquely allows you
to develop JavaScript using the strongly typed, compiled Java language
in Eclipse. This makes it the most valuable JavaScript development environment available
anywhere. It also has the nice feature to create 6 different flavours of your
JavaScript, each one optimised for a different popular web browser. This helps
your users get a really fast web experience.
Multiple Platforms
The NavWin MVP implements MVP properly, in the sense that
each application will work on the web or as a Windows application. In theory
you could extend this to any number of mediums (e.g. iPad applications). The
Windows version is used to allow fast development of the application (as the ‘compile
and run’ turn-around time is much faster than the web equivalent). The Web
version is for distribution on the web site.
General concepts
In order to support MVP on the web you need the following
basic elements:
1) A
concept of model (the logical database)
2) A
concept of view (the client side GUI which contains no business logic)
3) A
concept of data source (the physical database)
4) A
concept of presenter (which ties together the model, the view and the business
logic)
5) A
concept of a presenter router (Presenter mapping)
6) A
concept of location (URL mapping)
The Microsoft Visual Studio environment actually manages to
take you some of the way there, as it basically implements a key part of MVP
with its segregation of design code and presenter code in every form or user
control. This provides a useful starting point to extend to generic, web based
MVP.
Communicating with the client
In a web environment, the client is the web browser. In a
web environment, all communication between the client and the server is done
using Unicode text based messages. Therefore a structured text
based notation needs to be defined. This could be a pre-packaged notation, such
as JSON, however we have opted for an even more compact notation that allows
easy sequential parsing in JavaScript. The idea is to try to make the communication
cycle between the client and the server as short as possible to improve the
user experience.
Rendering the view in the client
As the view contains no business logic it is actually quite
easy to program the client. The client only needs to do 3 things:
1) Process
a load message (which defines the control layout and initial data)
2) Process
an update message (which defines new data and possibly new control layout)
3) Send
an event message (which will include the current state of the control data)
This is why it would be easy to plug in another client (such
as iPad) when using MVP.