We're on a roll ...
Milestone 1 delivered Reverse Ajax and other goodies. Milestone 2 adds Annotations, Reverse Ajax using Jetty Continuations, the ability to write your Javascript in Java and more.
Javascript puts some people off Ajax; DWR 2.0 milestone 2 has a set of new experimental APIs that allow you to use Java and the familiarity of the language and IDE to write Javascript.
The first is a server-side version of our own DWRUtil library:
import org.directwebremoting.proxy.dwrutil.DwrUtil; DwrUtil util = new DwrUtil(...); util.addOptions("selectId", array);
The code above is Java, but it alters what is seen in a remote web browser, in this case by adding the contents of a string array into a drop-down list.
We also have an experimental server-side Java version of Script.aculo.us Effects:
import org.directwebremoting.proxy.scriptaculous.Effect; Effect effect = new Effect(...); effect.fade("selectId");
The really neat thing is that you can combine these server-side APIs with Reverse Ajax to alter many browsers with a few calls.
Collection sessions = WebContextFactory.get().getScriptSessionsByPage("/index.html"); DwrUtil util = new DwrUtil(sessions); util.setValue("message", "Hello, World!");
This code will find all the browsers on the home page and alter the contents of a div with id="message" to contain a greeting. There is an example of this working in the Java Chat example included in the war file download. You can also view the source using FishEye.
We'll be looking to add more in the next few weeks. Tell us what you'd like on the mailing list.
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 <signature> element) you can use DWR without any need for dwr.xml. New annotations include @Create, @Convert, @RemoteMethod, @RemoteProperty.
For more detail see the annotations documentation.
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.
I'd like to expand the support to other servlet engines, but it looks like Jetty is quite a way ahead of the curve here. As I recently blogged, we need a JSR for Continuations to make this easy.
A number of security mechanisms automatically send a login page back to the user if some security constraint times out. We've added an experimental feature to allow you to take special action if something replaces a DWR response with a login screen.
Commonly you might want to reload the current page to get to see the login screen properly. You can do that as follows:
DWREngine.setTextHtmlHandler(function() { document.location.reload(); });
Milestone 2 has also fixed lots of bugs. If you've reported anything wrong recently, please have a go and report back.
You can download DWR 2.0 M2 from the usual download page.