DWR Plugin

  • Tags: rich client, ajax
  • Latest: 0.1
  • Last Updated: 18 June 2007
  • Grails version: *
  • Authors: Alex Shneyderman
1 vote
Dependency:
compile ":dwr:0.1"

 Documentation

Summary

Description

DWR Plugin

This plugin wraps around functionality provided by the DWR framework. Plugin is targeting version 2.0 of DWR. To learn more about DWR visit their site

Installation

From your application's directory issue the following command: 

grails install-plugin dwr

The operation requires network connection the first time you execute it, afterwards plugin will be cahced and you would be able to install it with no network available. When installation is complete you can use DWR features within your application. You would need to configure DWR for it to be usable. So, keep reading on how to do it.

If you are impatient you can download the demo, install the plugin into the demo application then run 'grails run-app' and you will have the demo accessible at /dwrdemo. 

Demo for the impatient

Download DWR demo application. The application is a Grails adaptation of the demo application that is(was) shipped with DWR.  The demo is developed with 0.6-SNAPSHOT, so if you use version less than that run grails upgrade (it will downgrade but it's all the same)

Configuration

Regularaly, DWR is configured by dwr.xml file that users place in WEB-INF directory of the web application. We configure DWR within grails a bit differently. The plugin provides a configuration builder. Here is a little sample of how one would configure an interface with it:

create(creator:'new', javascript:'AddressLookup') {
   param (name:'class') { 'uk.ltd.getahead.dwrdemo.address.AddressLookup' }
}
an equivalent dwr.xml definition would be:
<create creator="new" javascript="AddressLookup">
   <param name="class" value="uk.ltd.getahead.dwrdemo.address.AddressLookup" />
</create>
closure called dwrconfig. To give you an example of the complete syntax, here is how your bootstrap class might look like:
class DwrConfigBootStrap {

def init = { servletContext -> } def destroy = {}

def dwrconfig = { service(name:'testService', javascript:'TestService') { exclude('setMetaClass,getMetaClass,setProperty,getProperty') }

create(creator:'new', javascript:'AddressLookup') { param (name:'class') { 'uk.ltd.getahead.dwrdemo.address.AddressLookup' } } } }


Note, how dwrconfig closure contains an element that does not exists in dwr.xml - service. This is a feature that allows you to expose grails services. In the above example we are exposing a service named testService and its interface would be accessed to the browser through /dwr/interface/TestService.js . You can use all the inner elements that are meaningfull such as auth, include/exclude.

Version 0.1 - features

  • DWR config builder.
  • include/exclude calls accept a comma separated string of method names.
  • auth call's methods argument accepts a comma separated string of method names.
  • services can be exposed through service call.
  • convert calls, to declare converters.
  • signatures call accepts multi-line strings.
  • param call accepts multi-line string as its value parameter.

Requirements

  • Grails 0.6 and up is required for this plugin to work. Note, it might work with earlier version of grails but it was not tested.