views:

431

answers:

3

Can GWT be used just for simple AJAX? I dont want the widgets, I just want to avoid coding javascipt. What I need is simple ajax, like clicking on a link and updating the contents of a div with data retrieved from the server, or things like that. Can GWT be used for that purpouse? if so, where can I get some help? All I find on the web is based around the widgets.

+1  A: 

Definitely you can use GWT for just making a simple AJAX call. I mean that's what GWT is all about. Detailed information you get here: code.google.com/intl/en-EN/webtoolkit/doc/1.6/DevGuideServerCommunication.html

So basically you either Use the GWT-RPC mechanism or communicate with a server side service which might be plain XML, SOAP or REST based. Of cause you simple can load plain text as well...

In my opinion, if you want to do just an AJAX call and update a HTML element with the data you got from the response, it might be easier (less overhead) to use e.g. the Prototype JS library: http://www.prototypejs.org/api/ajax/updater

StefanS
+4  A: 

Yes indeed that is perfectly possible. The Widgets are only part of the story. You can use the RPC or RequestBuilder to handle server calls using RPC or JSON or XML. You can also use the DOM class and Element classes to manipulate the div blocks directly.

You gain the productivity tools of Java (Eclipse) and you also get the benefit of optimized Javascript code that should work on all supported browsers.

As for documentation you can find all you need in the javadocs: http://google-web-toolkit.googlecode.com/svn/javadoc/1.6/index.html?overview-summary.html

The relevant packages are:

com.google.gwt.dom.client (Document is what you need for DOM manipulations)
com.google.gwt.http.client if you want to send GETs/POSTs.
com.google.gwt.user.client which contains the Window class
com.google.gwt.json.client for sending/receiving json payloads to/from the server
com.google.gwt.xml.client in case you want to send/receive XML data and parse it on the client side.

David

David Nouls
Thank you David!
Damian
A: 

if you like jquery (but dont want to use javascript), there is a library for GWT that replicates that functionality called GWT Query, http://code.google.com/p/gwtquery/ .

Using that, you can update dom relatively easily, and yet still have the type safe checking of java, as well as the nice features of code obfuscation+minification for free.

Chii
Thanks for the tip, I'll give ir a try maybe
Damian