Chapter 8. Using RequestFactory
This chapter covers
GWT provides several ways for your data to communicate between the client and server. In chapter 7 we explored GWT-RPC, which as you saw is a great general-purpose tool that allows you to transport a Java object between client and server. In this chapter we move to a relative of GWT-RPC named RequestFactory. And this raises the question, how is RequestFactory different than GWT-RPC?
GWT-RPC was designed to be a generic service-based mechanism, whereas RequestFactory was designed to work specifically with data objects, which are usually database-persisted objects. So although you can use GWT-RPC with the database, certain aspects of it can make it a difficult fit for your project. Key features of RequestFactory include the following:
- No shared domain classes, facilitating easier integration with existing projects
- No servlet to write, and easier integration with dependency injection containers
- Only data diffs are communicated, providing improved performance
By “no shared domain” we mean that the domain classes live only on the server and aren’t accessed directly by code running in the browser. On the client side you instead use proxy classes, which GWT generates at compile time based on an interface contract.