(Updated 6/14 with links to the two parts of this step)
The next step in building a real world mortgage calculator using GWT is to retrieve something simple from a back end. (See the problem's introduction and Step #1, as well as the client code and the server code portions of the step described below.) It will be easiest to start with something simple. In this example, the client will pull two different mortgage interest rates (a 30 year fixed rate and a 5/25 ARM rate) from the Expresso back end. Since I am accessing a Java back end, there are two options.
RemoteServiceServlet
.
String
). The benefit of this method is that it's very familiar to folks who've used XMLHttpRequest and is relatively simple. The main downside is that you're limited to String
s as return values. There are, however, ways around that limit.Based on the current requirements, it made more sense to use HTTPRequest than Google services. I could see using the Google services layer if I were doing some green field development in Java, or in a situation where such transparent marshaling saved a significant deal of work.
Of course, when you're sending back text, you have a couple of options for encoding the data. I considered a custom encoding, but that's not very scalable to large datasets, escaping and unescaping can be non trivial, and there are well known text transfer formats out there. Of those I know, XML and JSON are the primary ones. I went with JSON because Google kindly (almost) provides a JSON parsing library in their sample code. This parsing library is nice because it allows me to send back values as String
s, Array
s, Boolean
s, Number
s or Objects
s and converts the JSON to the appropriate type. I say almost because I had to make a few changes to their code.
In my next post, I'll look at the server side changes I made, including integrating the JSON.Simple Java library into Expresso.
Posted by moore at June 12, 2006 04:33 PM