[英]What is the best way to use Ext JS as part of Java / Spring / Hibernate based web application?
We want to try Ext JS on new project.我们想在新项目上尝试 Ext JS。 Is there any well-known best practice for integrating Ext JS with server side Java (Spring/Hibernate/JS) application?将 Ext JS 与服务器端 Java (Spring/Hibernate/JS) 应用程序集成是否有任何众所周知的最佳实践? Is DWR a good choice for that? DWR 是一个不错的选择吗?
My team has been using Ext with DWR for almost year a year, and have had nothing but good things to say.我的团队几乎一年都在使用 Ext 和 DWR,除了好话外,没有什么可说的。 If you take this approach, you will end up using DWR's generated JavaScript classes for making your requests to the server.如果您采用这种方法,您最终将使用 DWR 生成的 JavaScript 类向服务器发出请求。 This will often be done in place of using the Ext.Ajax and Ext.data.Connection classes.这通常会代替使用 Ext.Ajax 和 Ext.data.Connection 类来完成。 When you use a class that require an Ext.data.Store (eg 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.当您使用需要 Ext.data.Store(例如手柄、组合框等)的 class 并且想要从服务器获取数据时,您需要使用可以与 DWR 链接的代理。 The user-community provided Ext.ux.data.DWRProxy has worked flawlessly for us: http://extjs.com/forum/showthread.php?t=23884 .用户社区提供的 Ext.ux.data.DWRProxy 为我们完美地工作: http://extjs.com/forum/showthread.php?t=23884 。
Yes it's possible.是的,这是可能的。
I've done the same thing with .NET: UI in ext-JS which communicates with the server trough JSON.我对 .NET 做了同样的事情:ext-JS 中的 UI 通过 JSON 与服务器通信。 In .NET world you can use DataContractSerializer (class from WCF) or JavascriptSerializer (ASP.NET)在 .NET 世界中,您可以使用 DataContractSerializer(来自 WCF 的类)或 JavascriptSerializer(ASP.NET)
I'm sure that there's several good JSON Serializer in the Java world too.我确信在 Java 世界中也有几个不错的 JSON 串行器。 I used Jabsorb (but not enough to give you a solid feedback).我使用了 Jabsorb (但不足以给你一个可靠的反馈)。 It appears that other people have tried: [link text][2]似乎其他人已经尝试过:[链接文本][2]
[2]: http://extjs.com/forum/showthread.php?t=30759 forum ext-js [2]: http://extjs.com/forum/showthread.php?t=30759论坛 ext-js
In our application we subclass Ext.data.DataProxy like this:在我们的应用程序中,我们像这样子类Ext.data.DataProxy :
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.我们的实际代理 class 有一些额外的调试和错误处理代码,为了简单起见,我省略了这些代码。 You may also need to manipulate your data slightly so that the Ext.data.JsonReader can handle it, but that's the basic idea.您可能还需要稍微操作您的数据,以便Ext.data.JsonReader可以处理它,但这是基本思想。 SomeService is the JavaScript name you specified for whatever bean you exposed in dwr.xml (or your Spring config). SomeService 是您为在 dwr.xml (或您的 Spring 配置)中公开的任何 bean 指定的 JavaScript 名称。
Take a look at Grails, it plays well together with ExtJS.看看 Grails,它与 ExtJS 配合得很好。
It's perfectly fine to build your application using Ext JS/DWR/Spring/Hibernate.使用 Ext JS/DWR/Spring/Hibernate 构建您的应用程序非常好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.