Activate your free membership today | Log-in

Monday, September 4th, 2006

Bridging Java Swing with Ajax

Category: Ajax, Java

<p>Richard Bair of Sun Microsystems has created XMLHttpRequest and JSONHttpRequest beans, both part of the SwingX-WS project.

Interestingly Richard "ased the design and implementation on the W3C Working Draft Specification for XMLHttpRequest. So the good news is, for those of you familiar with XHR, you have essentially the same API available now for your Swing apps."

This is pretty pragmatic. We all know that XHR may not be the best API in the world, but Richard see's that a lot of people now know it, so he created something similar on the Swing side (Maybe we will see ProtoSwing or DojoSwing to give a nice wrapper?).

Here is an example in code. Java code remember:

JAVA:
  1.  
  2.         final HttpRequest req = new HttpRequest();
  3.         req.addOnReadyStateChangedListener(new PropertyChangeListener() {
  4.             public void propertyChange(PropertyChangeEvent evt) {
  5.                 if (evt.getNewValue() == ReadyState.LOADED) {
  6.                     String response = req.getResponseText();
  7.                     //do what you like with the response here
  8.                     //for example, if the XML was XMLDecoder
  9.                     //compatible:
  10.                     java.beans.XMLDecoder decoder = new java.beans.XMLDecoder(
  11.                         new ByteArrayInputStream(response.getBytes()));
  12.                     Customer c = (Customer)decoder.readObject();
  13.                     decoder.close();
  14.                 }
  15.             }
  16.         });
  17.         try {
  18.             req.open(HttpMethod.GET, new URL("http://MyCompany.com/someService?customer="A2342DAD"/"));
  19.             req.send();
  20.         } catch (Exception e) {
  21.             e.printStackTrace();
  22.         }
  23.  

Related Content:

  • Adobe builds a bridge to Ajax
    Adobe Systems Inc. is trying to make it easier to integrate Flex into Ajax applications with a new JavaScript library designed to save developers time...
  • At JavaOne: Tibco talks Ajax and event-driven SOA
    At JavaOne this week, Tibco Software Inc. unveiled its planned Ajax Message Service (AMS), which is designed to provide event-driven SOA by pushing...
  • IceSoft betas JavaScript-free Ajax tool
    A beta release of ICEFaces Community Edition, an Ajax development tool for Java coders, was released this week by IceSoft Technologies, Inc. The...
  • Microsoft passes OpenAjax tests
    Microsoft announced it passed the OpenAjax InteropFest 1.0 tests and is interoperable with other Ajax components in the OpenAjax ecosystem through the...
  • Sun gets serious about Ajax
    Sun Microsystems Inc. demonstrates a commitment to Ajax with its new involvement with to alliances working on Ajax technology, the OpenAJAX Alliance...

Posted by Dion Almaer at 2:24 pm
4 Comments

+++--
3.6 rating from 46 votes

4 Comments »

Comments feed TrackBack URI

wow, I feel like I just had a Fearsome Premavision of what javascript would be like if it was, you know… strictly typed.

=X

Comment by henrah — September 4, 2006

:) yes..a downward and backward leap made for ? reason…swing already sucked enough as it was….lol

Comment by Jesse Kuhnert — September 4, 2006

Any JS programmer who directly uses XHR, instead of a simple library call like call(“/cats”, feedPet) needs to make a pretty strong justification for it.

Comment by Michael Mahemoff — September 5, 2006

This is the best article abou Java Swing with Ajax

Comment by Počasí — December 2, 2006

Leave a comment

You must be logged in to post a comment.