Tag Archives: Java

Is Java bad? Ask Ajaxian…

Ajaxian has once again a new Post about a new Library, this time a URL Parser. All nice and shiny but it isn’t the library I want to write about, it’s the finishing comment they put in there:
This smells like a Java group writing JavaScript to me with the camelCase and thus p.getUsername() instead of p.username.
Why should it be negative to immitate Java? I’m a Java-Programmer myself and I try to use as much as I can from my experience when writing Ajax applications. I think the Ajax community could learn a lot from the Java style of doing things instead of being so snobbish…
Did you like this? Share it:

YUI Blog on JavaScript

Even if you aren’t a user of the Yahoo User Interface library this post from
Do not use new Function to create function values. Use function expressions instead. For example,
frames[0].onfocus = new Function("document.bgColor='antiquewhite'")
is better written as
frames[0].onfocus = function () {document.bgColor = 'antiquewhite';};
The second form allows the compiler to see the function body sooner, so any errors in it will be detected sooner. Sometimes new Function is used by people who do not understand how inner functions work.
Did you like this? Share it:

Integrating Maps into Your Java Web Application with Google Maps and Ajax

John Ferguson Smart has written a great tutorial about how to integrate the Google Maps API with Java Servlets. He starts off with the usual introduction to Ajax, but soon goes on to more interesting topics, and after just a few lines he already has a fully functional Map in his application.
 
function load() {
   if (GBrowserIsCompatible()) {
     var map = new GMap2(document.getElementById("map"));
     map.setCenter(new GLatLng(-41.5, -187.5), 5);
     map.addControl(new GSmallMapControl());
     map.addControl(new GOverviewMapControl());
   }
 }
Details are then added a few at a time, and what he ends up with is a fully fledged Maps Application, with asynchronous fetching of data and detail Overlays.
 
function processSiteData(xmlDoc){
  // obtain the array of markers and loop through it
  siteMarkers = xmlDoc.documentElement.getElementsByTagName("marker");
  displaySitesMarkers();
}
function displaySitesMarkers() {
   map.clearOverlays();
   for (var i = 0; i < siteMarkers.length; i++) {
     // obtain the attributes of each marker
     var lat = parseFloat(siteMarkers[i].getElementsByTagName("latitude")[0].firstChild.nodeValue);
     var lng = parseFloat(siteMarkers[i].getElementsByTagName("longitude")[0].firstChild.nodeValue);    
     var id = siteMarkers[i].getElementsByTagName("id")[0].firstChild.nodeValue;
     var label = siteMarkers[i].getElementsByTagName("name")[0].firstChild.nodeValue;    
     createSiteMarker(new GLatLng(lat,lng),label,id);
   }
}
All is explained step by step and is really easy to follow, if only all tutorials were this easy :)
Google Maps in action
P.S.: I like people that aren’t too shy to add some humour to their posts:
Of course, the advantage of storing geographical site coordinates in a database is that they can be updated as necessary; for example, in the case of a major earthquake or land slide, or continental drift, or to keep track of the famous migrating mud-transporting camel caravans of the central Elbonian steppes.
Did you like this? Share it:

Hands on DWR

I’m so sad that I couldn’t see this speach:

Joe Walker (Getahead-DWR) and Bram Smeets (Interface 21-Spring) took a novel approach to their “Hands on DWR” talk at The Ajax Experience: Creating a game – “Multi Player Battleships” live in the session.

The concept was very well received – many smiles around the room when the idea was introduced. With Joe talking and Bram typing they took a pre-created boilerplate (configuration and some of the simpler tasks completed beforehand due to the time constraint) and turned it into a simple, but fully functional, multiplayer game.

I’m happy to report that I don’t have an awful lot to report regarding the complex inner workings of the application. Those familiar with DWR will find that the code contains few things unfamiliar or even ‘advanced’. As someone with only an intermediate DWR skillset – I had no trouble following the code Joe and Bram were creating. The final product was simple but functional – intentionally avoiding features that would improve the game but cloud the demo. Joe and Bram were able to hide from each other, fire, and even chat as they played. The code for the demo can be found here (near the bottom at the time of this post).

The most contested point was the use of “reverse ajax” to sync with the current server status at timed intervals. Reverse Ajax was introduced in v2.0 m1 (current stable release is v1.1.3) Concerns centered on potential security issues – Joe explained that they do as much as reasonably possible to stop malicious users, but in the end if you are a malicious user: there are many ways that you can bring the server down without DWR.

image stolen from this post on Joe’s blog where he also talks about the concept of developing the game live in a session

Especially because I’m currently using DWR for some minor projects and I just love it :)
Did you like this? Share it:

Google Web Toolkit – Performance and Interoperability

The Google Web Toolkit (GWT) is Google’s solution to making Ajax development easy for Java programmers. Google’s Bruce Johnson spoke about GWT at The Ajax Experience on Monday.

Advertisement BadgeIt’s now fairly easy to enter an online web design program if you want to increase your web design knowledge.

As we all know, Ajax development introduces some complexities (browser incompatabilities, managing numerous technologies within the page, etc.). GWT is a Java framework that nearly eliminates these complexities from the Java developer’s radar. Using GWT, the Java developer writes Java code that is compiled into Ajax-enabled pages by the GWT compiler. The compiler generates HTML and JavaScript that works in all major browsers while hiding many of the messy details from the Java developer.

Other highlights of Bruce’s presentation included:

  • Numerous demonstrations that showed simple Ajax-enabled applications generated with a small amount of Java code
  • Easy management of history and bookmarking inside of the Ajax application
  • Interoperability (GWT-generated code is easily integrated into existing pages)
  • An overview of the JavaScript Native Interface (JSNI) which enables the developer to include JavaScript libraries in their GWT Java source.
[via Ajaxian]
Did you like this? Share it: