tags:

views:

3048

answers:

5

Have you tried using MVC or any other UI pattern for GWT client code. What are the pitfalls/advantages you've faced in different approaches?

+2  A: 

The MVC pattern for GWT is discussed in this question, which also has a link to this in-depth blog post.

The only thing I'd add is that the client side code in its entirety can be be considered the "V" in "MVC", which may alter the way you look at it. Thinking of the client side code as its own nested MVC component, well, it's Java, it's object oriented, so it can be designed much like a Swing app. I think it is to your advantage to pull as much Controller code out of the View as possible to handle the GWT RPC stuff. The Model is sometimes more problematic, because you may have to decide if you want it on the server instead of the client. Or create a Model proxy, etc.

Glenn
+4  A: 

I think you need to treat GWT just like any other UI framework, like Swing, Cocoa, etc. Everything that makes sense in those frameworks in terms of MVC (or other paradigms) makes sense in GWT as well. I think sometimes people take the MVC thing too far, and I like the way it works in Cocoa more than most frameworks. You create a view, you have a ViewController that controls all the behaviour of the view, and then you have model objects with all your data. I don't think you need to be dogmatic about where all of your business logic is, it just needs to be where it makes sense.

In terms of pitfalls,the main one you will run into is that GWT is purely a front end technology, so technically the back end is sitting on a server somewhere. I don't see this as being that different to writing a client server swing application, that stores it's data in the cloud somewhere. The difference is that GWT is compiled down into javascript, and has all the limitations of a javascript web application, so there will be some things that you simply cannot do on the front end. Let's say for example you want to create a PDF and show that to the user, you can't do that in GWT, you need to call the back end to do it for you. In a Swing app on the other hand you could probably use itext and do it on the client side.

rustyshelf
A: 

Have you tried GWTruts (http://sourceforge.net/projects/gwtruts/)? It is also an open source GWT MVC framework which separate View and Controller in GWT

+1  A: 

http://code.google.com/p/gwt-mvc/ could help you.

The advantages are :

  • easy to read controller
  • History Tokens management
  • Controllers are testble with JMock (but not GwtTestCase)
  • Hierarchical MVC
  • Simple inheritance to start coding your view, controllers and models.
François Wauquier
A: 

Using some sort of MVC/MVP type pattern is really important when GWT apps get beyond the smallest project else you just loose control of what is going on.

Apart from what already has been mentioned there is also GXT's MVC implementation which I have looked at here: http://www.bristol-gtug.org/?p=45

This talk at Google IO last year started a lot of people off thinking about MVC/MVP on GWT: http://code.google.com/events/io/2009/sessions/GoogleWebToolkitBestPractices.html.

I recently noticed that there is also now an tutorial on MVP architecture in the GWT documentation which is a good start: http://code.google.com/webtoolkit/doc/latest/tutorial/mvp-architecture.html

Daniel Vaughan