Monday, September 4th, 2006
Bridging Java Swing with Ajax
<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:
-
-
final HttpRequest req = new HttpRequest();
-
if (evt.getNewValue() == ReadyState.LOADED) {
-
//do what you like with the response here
-
//for example, if the XML was XMLDecoder
-
//compatible:
-
java.beans.XMLDecoder decoder = new java.beans.XMLDecoder(
-
Customer c = (Customer)decoder.readObject();
-
decoder.close();
-
}
-
}
-
});
-
try {
-
req.send();
-
e.printStackTrace();
-
}
-
Related Content:











wow, I feel like I just had a Fearsome Premavision of what javascript would be like if it was, you know… strictly typed.
=X
:) yes..a downward and backward leap made for ? reason…swing already sucked enough as it was….lol
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.
This is the best article abou Java Swing with Ajax