<< 03 March 2008 | Home | 05 March 2008 >>

DWR + Aptana Jaxer

I've been working with the guys from Aptana for the past week or so on adapting DWR to be a remoting layer for Jaxer.

jaxer page flow

Jaxer is a way to run JavaScript on the server. But it's not just JavaScript as an alternative to Java/Ruby/PHP/etc. Jaxer is Mozilla, on the server, with it's face ripped off and replaced by a snorkel to serialize the DOM to a web browser. John has a great introduction, or there's the podcast that Ajaxian did.

The vision with DWR was always to say: We've got Javascript in the browser, and Java on the server - lets connect them in the best possible way. This leads to the migration of view logic from the server to the client. But it's not safe to move it all; Validation is part of view logic, but that needs to be done on the server. With Jaxer you can specify scripts to be runat="server" or runat="both" to allow validation or other logic to be run in both places.

Some of the changes that we've made to DWR will only help you if you are using DWR inside Jaxer, but others could be generally useful.

There are 2 basic changes. DWR on the Internet needs to make sure that the Internet only touches the code that you want it to touch. DWR in Jaxer doesn't have this problem because it's not accessible from the Internet, so we can do away with almost all configuration. Secondly latency inside a server-room is tiny compared with the net, which makes synchronous XHR viable.

So as it stands at the moment in development, you can use DWR inside Jaxer like this (clearly this is subject to change):

<script type='text/javascript' runat="server">
Jaxer.dwr.pathToDwrServlet = "http://localhost:8080/demoServer/dwr";
Jaxer.dwr.require("util", "new/org.example.Demo");

function loadServer() {
  var data = Demo.getData();
  dwr.util.setValue('fillFromServer', data);
}
</script>

There are a number of benefits that come out of this even if you're not using Jaxer:

  • In dwr.xml you needed to specify javascript='ScriptName'. If (as is common) ScriptName == Class.getShortName then you can just drop the attribute, it will default properly.
  • Cross domain remoting is now automatically detected, and scriptTag remoting is used if needed.
  • There is a new init-param 'useAbsolutePaths' which might help people with trouble remapping DWR's location.
  • All URLs are now reconfigurable.
  • If you are using DWR in synchronous mode (which I don't recommend on the Internet) then you can use returned data in the normal way without needing a callback.

IWebMvc Preview

Jose Noheda has released a preview of a library that glues together DWR, Dojo, Spring and Hibernate/JPA. It's a 0.1 release and he's looking for feedback.

Despite the name, it's not really another Web MVC framework, but more along the lines of AppFuse or Grails, as a way to kick-start a project and provide some sensible defaults without needing to learn everything from scratch.

The source and release notes say it needs 1.6, so Mac heads will need to get the Apple Java6 preview.

Jose's aims:

In my mind what I really needed was a platform that:

  • Is based on Java
    Although supporting Groovy / JRuby is a plus
  • Helps me to kick start a project
    But simplifying the process by giving me the best (and this can be tricky) set of frameworks for each task
  • Integrates both server and client sides
    And it's lightweight, robust and extensible. Read enterprise quality.
  • Supports all the common tasks a web app has to handle
    I include here: User Management, CRUD operations, i18n support (both framework & data), AJAX and astounding visuals

Jose has done some brilliant work on DWR. He created a large chunk of our binary file support, and is currently the Spring integration maintainer, so it might be worth a download to see if it can help you.

Tags :