DWR version 2.0 milestone 2: Write Javascript using Java

Along the same lines as my haXe post here’s an update to DWR that means you aren’t writing javascirpt directly anymore. Via Ajaxian.

Milestone 2 contains some great new features like Annotation based configuration and a customization to allow Reverse Ajax to use Jetty Continuations.

It also contains an experimental new feature to let you write Javascript using a Java API. Read on for how it works and why it can allow you to do some neat things.

Annotations: If you are using Java 5 then you can make use of the new DWR annotations thanks to Maik Schreiber. Combined with support for generic type reflection in milestone 1 (to get rid of the need for a element) you can use DWR without any need for dwr.xml. For more detail see the annotations documentation.

Jetty Continuations: The ongoing work with Reverse Ajax is to ensure that no webservers get hurt as a result of the extra load. The first piece of the puzzle is from Greg Wilkins of Jetty fame. If Reverse Ajax is turned on in a Jetty servlet engine then DWR will automatically use Jetty’s Ajax Continuations to save on server threads.

Write Javascript in Java: The New Java APIs create Javascript which is executed on the browser. We’ve started with DWRUtil and Scriptaculous Effects.

There are several reasons why you might want to do this:

  • DWR can use it’s Reverse Ajax feature to make your calls affect several browsers at the same time. This make writing Chat type apps quite easy.
  • My experience so far is that in many cases the Java code is easier to understand and shorter than the Javascript version.
  • Many people are put off DWR because it is Javascript heavy. This could help them out.
  • See the full release notes for more details on this and other features, with some examples of writing Javascript in Java.

    Please note that this API is very experimental so we’re not totally sure that we should implement it as we have done, or even if it is a good idea at all. I’m interested in your feedback.