views:

2495

answers:

5

We want to try Ext JS on new project. Is there any well-known best practice for integrating Ext JS with server side Java (Spring/Hibernate/JS) application? Is DWR a good choice for that?

A: 

It's perfectly fine to build your application using Ext JS/DWR/Spring/Hibernate.

sapporo
+1  A: 

Yes it's possible.

I've done the same thing with .NET : UI in ext-JS which communicates with the server trough JSON. In .NET world you can use DataContractSerializer (class from WCF) or JavascriptSerializer (ASP.NET)

I'm sure that there's several good JSON Serializer in the Java world too. I used Jabsorb (but not enough to give you a solid feedback). It appears that other people have tried : [link text][2]

[2]: http://extjs.com/forum/showthread.php?t=30759 forum ext-js

Matthieu
+1  A: 

In our application we subclass Ext.data.DataProxy like this:

var MyProxy = function(fn) {
  this.fn = fn;
};
Ext.extend( MyProxy, Ext.data.DataProxy, {
  load: function(params,reader,callback,scope,arg) {
    this.fn(params,function(data) {
      callback.call(scope,reader.readRecords(data),arg,true);
    });
  },
  update: function() {}
});

You use it with a store like so:

var store = new Ext.data.Store({
  reader: myReader, proxy: new MyProxy(function(params,callback) {
    // params are used for paging and searching, if you need it
    callback(SomeService.getData(params));
  })
  // ...
});

Our actual proxy class has some additional debug and error handling code that I left out for simplicity. You may also need to manipulate your data slightly so that the Ext.data.JsonReader can handle it, but that's the basic idea. SomeService is the JavaScript name you specified for whatever bean you exposed in dwr.xml (or your Spring config).

noah
+4  A: 

My team has been using Ext with DWR for almost year a year, and have had nothing but good things to say. If you take this approach, you will end up using DWR's generated JavaScript classes for making your requests to the server. This will often be done in place of using the Ext.Ajax and Ext.data.Connection classes. When you use a class that require an Ext.data.Store (e.g. grip, combo box, etc.) and you want to fetch data from the server, you will need to use a proxy that can link in with DWR. The user-community provided Ext.ux.data.DWRProxy has worked flawlessly for us: http://extjs.com/forum/showthread.php?t=23884.

big lep
Just wanted to report that we are doing this now and it works quite good. We also are using DWRProxy just like suggested.
Igor Romanov
A: 

Take a look at Grails, it plays well together with ExtJS.

ammoQ