-->

Best architecture for applications in GWT

2020-08-01 05:23发布

问题:

I'm starting to study GWT now, and have a very general question, I could maybe teach myself with a little more experience, but I don't want to start it wrong, so I decided to ask you.

I always develop using JSF, having separate packages for beans, controllers and managedbeans.

However, as the GWT uses RPC, I will not have managedbeans, right? So, GWT automatically handles user session for me, or do I have to do it myself?

What is the best package structure for the project?

It is best to use RPC, or create a webservice and access the webservice in GWT?

It's hard to host the application on a tomcat server?

Is there a test saying which server is faster for GWT?

Thank you.

回答1:

However, as the GWT uses RPC, I will not have managedbeans, right? 

True, GWT RPC uses POJOs.

So, GWT automatically handles user session for me, or do I have to do it myself?

GWT is pure AJAX APP - client code (normally) runs in one browser window (similar to gmail) and does not reload the web page. This means that the application state is always there - no need for sessions (as a means of saving state). You still might need sessions for user authentication, but this is usually handled by servlet container.

What is the best package structure for the project?

Three packages: client, server and shared. Client for GWT client code, server for server (also RPC) code and shared for POJOs that are used by both client and server.

It is best to use RPC, or create a webservice and access the webservice in GWT?

Go with GWT-RPC or (better, newer) with RequestFactory.

It's hard to host the application on a tomcat server?

It's straightforward: GWT client code is compiled to JS/html and is hosted as any static content. RPC server code is just Servlets - normal web.xml registration.

Is there a test saying which server is faster for GWT?

No clue, but IMHO does not matter, because most of the latency will come from database and network.



回答2:

Also have a look at http://code.google.com/p/gwt-platform/

This framework is really great and follow all suggested best practices(e.g. MVP) by google and give you as well great support for gin, gwt dispatcher, website crawling, history with tokens, code splitting via gwt async etc.

If you want to set up a good project structure try to use the maven gwt plugin(http://mojo.codehaus.org/gwt-maven-plugin/) it helps you a lot with setting up an initial structure and manage your build process.