- 浏览: 110236 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
0c0c0f:
原来如此str.replaceAll("[\\x00 ...
xml中的非法字符 -
twlkyao:
谢谢,问题解决了。
xxx is not in the sudoers file解决方法 -
guanshubang:
czxvxcv[b][/b]
在eclipse中使用junit -
帅先勃:
...
Java设计模式之生产者消费者模式 -
liberD:
我昨天试了,报了很多的错误。请问,您遇到这种情况了吗?
git安装
At this point, the client code should start to compile but there is still more to do before we can run it. We need some utility classes for the dispatcher and Gin:
CachingDispatchAsync.java
view source
<object id="highlighter_932213_clipboard" title="copy to clipboard" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="16" height="16" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" type="application/x-shockwave-flash"> </object>
print? 01.
package
co.uk.hivedevelopment.greet.client;
02.
import
java.util.HashMap;
03.
import
java.util.Map;
04.
import
com.google.gwt.user.client.rpc.AsyncCallback;
05.
import
com.google.inject.Inject;
06.
import
net.customware.gwt.dispatch.client.DispatchAsync;
07.
import
net.customware.gwt.dispatch.shared.Action;
08.
import
net.customware.gwt.dispatch.shared.Result;
09.
/**
10.
* Dispatcher which support caching of data in memory
11.
*
12.
*/
13.
public
class
CachingDispatchAsync
implements
DispatchAsync {
14.
private
DispatchAsync dispatcher;
15.
private
Map, Result> cache =
new
HashMap, Result>();
16.
@Inject
17.
public
CachingDispatchAsync(
final
DispatchAsync dispatcher) {
18.
this
.dispatcher = dispatcher;
19.
}
20.
/*
21.
* (non-Javadoc)
22.
* @see net.customware.gwt.dispatch.client.DispatchAsync#execute(A, com.google.gwt.user.client.rpc.AsyncCallback)
23.
*/
24.
public
, R
extends
Result>
void
execute(
final
A action,
final
AsyncCallback callback) {
25.
dispatcher.execute(action, callback);
26.
}
27.
/**
28.
* Execute the give Action. If the Action was executed before it will get fetched from the cache
29.
*
30.
* @param Action implementation
31.
* @param Result implementation
32.
* @param action the action
33.
* @param callback the callback
34.
*/
35.
@SuppressWarnings
(
"unchecked"
)
36.
public
, R
extends
Result>
void
executeWithCache(
final
A action,
final
AsyncCallback callback) {
37.
final
Result r = cache.get(action);
38.
39.
if
(r !=
null
) {
40.
callback.onSuccess((R) r);
41.
}
42.
else
{
43.
dispatcher.execute(action,
new
AsyncCallback() {
44.
public
void
onFailure(Throwable caught) {
45.
callback.onFailure(caught);
46.
}
47.
public
void
onSuccess(R result) {
48.
cache.put((Action) action, (Result) result);
49.
callback.onSuccess(result);
50.
}
51.
});
52.
}
53.
}
54.
/**
55.
* Clear the cache
56.
*/
57.
public
void
clear() {
58.
cache.clear();
59.
}
60.
}
GreetingClientModule.java
view source
<object id="highlighter_727479_clipboard" title="copy to clipboard" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="16" height="16" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" type="application/x-shockwave-flash"> </object>
print? 01.
package
co.uk.hivedevelopment.greet.client.gin;
02.
import
net.customware.gwt.presenter.client.DefaultEventBus;
03.
import
net.customware.gwt.presenter.client.EventBus;
04.
import
net.customware.gwt.presenter.client.gin.AbstractPresenterModule;
05.
import
net.customware.gwt.presenter.client.place.PlaceManager;
06.
import
co.uk.hivedevelopment.greet.client.CachingDispatchAsync;
07.
import
co.uk.hivedevelopment.greet.client.mvp.AppPresenter;
08.
import
co.uk.hivedevelopment.greet.client.mvp.GreetingPresenter;
09.
import
co.uk.hivedevelopment.greet.client.mvp.GreetingResponsePresenter;
10.
import
co.uk.hivedevelopment.greet.client.mvp.GreetingResponseView;
11.
import
co.uk.hivedevelopment.greet.client.mvp.GreetingView;
12.
import
com.google.inject.Singleton;
13.
public
class
GreetingClientModule
extends
AbstractPresenterModule {
14.
@Override
15.
protected
void
configure() {
16.
bind(EventBus.
class
).to(DefaultEventBus.
class
).in(Singleton.
class
);
17.
bind(PlaceManager.
class
).in(Singleton.
class
);
18.
19.
bindPresenter(GreetingPresenter.
class
, GreetingPresenter.Display.
class
, GreetingView.
class
);
20.
bindPresenter(GreetingResponsePresenter.
class
, GreetingResponsePresenter.Display.
class
, GreetingResponseView.
class
);
21.
22.
bind(AppPresenter.
class
).in(Singleton.
class
);
23.
bind(CachingDispatchAsync.
class
);
24.
}
25.
}
GreetingGinjector.java
view source
<object id="highlighter_347758_clipboard" title="copy to clipboard" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="16" height="16" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" type="application/x-shockwave-flash"> </object>
print? 01.
package
co.uk.hivedevelopment.greet.client.gin;
02.
import
net.customware.gwt.dispatch.client.gin.ClientDispatchModule;
03.
import
net.customware.gwt.presenter.client.place.PlaceManager;
04.
import
co.uk.hivedevelopment.greet.client.mvp.AppPresenter;
05.
import
com.google.gwt.inject.client.GinModules;
06.
import
com.google.gwt.inject.client.Ginjector;
07.
@GinModules
({ ClientDispatchModule.
class
, GreetingClientModule.
class
})
08.
public
interface
GreetingGinjector
extends
Ginjector {
09.
AppPresenter getAppPresenter();
10.
PlaceManager getPlaceManager();
11.
}
Now we tie all this together by replacing the existing module entry class with the following:
GreetMvp.java
view source
<object id="highlighter_318282_clipboard" title="copy to clipboard" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="16" height="16" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" type="application/x-shockwave-flash"> </object>
print? 01.
package
co.uk.hivedevelopment.greet.client;
02.
import
co.uk.hivedevelopment.greet.client.gin.GreetingGinjector;
03.
import
co.uk.hivedevelopment.greet.client.mvp.AppPresenter;
04.
import
com.google.gwt.core.client.EntryPoint;
05.
import
com.google.gwt.core.client.GWT;
06.
import
com.google.gwt.user.client.ui.RootPanel;
07.
public
class
GreetMvp
implements
EntryPoint {
08.
private
final
GreetingGinjector injector = GWT.create(GreetingGinjector.
class
);
09.
public
void
onModuleLoad() {
10.
final
AppPresenter appPresenter = injector.getAppPresenter();
11.
appPresenter.go(RootPanel.get());
12.
injector.getPlaceManager().fireCurrentPlace();
13.
}
14.
}
Server Components
Okay, now let's define the server side. We need to configure Guice and the dispatch handler plus we need to provide an implementation for the SendGreeting action.
SendGreetingHandler.java
view source
<object id="highlighter_877314_clipboard" title="copy to clipboard" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="16" height="16" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" type="application/x-shockwave-flash"> </object>
print? 01.
package
co.uk.hivedevelopment.greet.server.handler;
02.
import
javax.servlet.ServletContext;
03.
import
javax.servlet.http.HttpServletRequest;
04.
import
net.customware.gwt.dispatch.server.ActionHandler;
05.
import
net.customware.gwt.dispatch.server.ExecutionContext;
06.
import
net.customware.gwt.dispatch.shared.ActionException;
07.
import
org.apache.commons.logging.Log;
08.
import
co.uk.hivedevelopment.greet.shared.rpc.SendGreeting;
09.
import
co.uk.hivedevelopment.greet.shared.rpc.SendGreetingResult;
10.
import
com.google.inject.Inject;
11.
import
com.google.inject.Provider;
12.
public
class
SendGreetingHandler
implements
ActionHandler<SendGreeting, SendGreetingResult> {
13.
private
final
Log logger;
14.
private
final
Provider<ServletContext> servletContext;
15.
private
final
Provider<HttpServletRequest> servletRequest;
16.
@Inject
17.
public
SendGreetingHandler(
final
Log logger,
18.
final
Provider<ServletContext> servletContext,
19.
final
Provider<HttpServletRequest> servletRequest) {
20.
this
.logger = logger;
21.
this
.servletContext = servletContext;
22.
this
.servletRequest = servletRequest;
23.
}
24.
@Override
25.
public
SendGreetingResult execute(
final
SendGreeting action,
26.
final
ExecutionContext context)
throws
ActionException {
27.
final
String name = action.getName();
28.
29.
try
{
30.
String serverInfo = servletContext.get().getServerInfo();
31.
32.
String userAgent = servletRequest.get().getHeader(
"User-Agent"
);
33.
34.
final
String message =
"Hello, "
+ name + "!
35.
I am running " + serverInfo
36.
+ ".
37.
It looks like you are using:
38.
" + userAgent;
39.
40.
//final String message = "Hello " + action.getName();
41.
42.
return
new
SendGreetingResult(name, message);
43.
}
44.
catch
(Exception cause) {
45.
logger.error(
"Unable to send message"
, cause);
46.
47.
throw
new
ActionException(cause);
48.
}
49.
}
50.
@Override
51.
public
void
rollback(
final
SendGreeting action,
52.
final
SendGreetingResult result,
53.
final
ExecutionContext context)
throws
ActionException {
54.
// Nothing to do here
55.
}
56.
57.
@Override
58.
public
Class<SendGreeting> getActionType() {
59.
return
SendGreeting.
class
;
60.
}
61.
}
DispatchServletModule.java
view source
<object id="highlighter_506662_clipboard" title="copy to clipboard" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="16" height="16" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" type="application/x-shockwave-flash"> </object>
print? 01.
package
co.uk.hivedevelopment.greet.server.guice;
02.
import
net.customware.gwt.dispatch.server.service.DispatchServiceServlet;
03.
import
com.google.inject.servlet.ServletModule;
04.
public
class
DispatchServletModule
extends
ServletModule {
05.
@Override
06.
public
void
configureServlets() {
07.
// NOTE: the servlet context will probably need changing
08.
serve(
"/greetmvp/dispatch"
).with(DispatchServiceServlet.
class
);
09.
}
10.
}
发表评论
-
git安装
2011-07-05 17:39 1910linux 安装git 2011-01-06 10:01 ... -
myeclipse8.0GA CDkey
2010-05-24 13:33 1167Subscriber:MaYong Subscript ... -
svn无法更新,问题解决方法
2010-03-29 10:23 11165Working copy’**’locked. Please ... -
xml中的非法字符
2010-03-10 18:06 13862今使用Jdom生成xml文件的时候,总是出现0x0,0x8为非 ... -
mysql 添加访问权限
2010-03-10 15:11 1567记录下来,省得以后找不到。 shell>mysq ... -
xxx is not in the sudoers file解决方法
2010-01-11 11:19 5056用sudo时提示"xxx is not in t ... -
Session ID and Cookie
2010-01-08 14:59 3196具体来说cookie机制采用 ... -
Google Web Toolkit (GWT) MVP Example (5)
2009-11-24 18:13 1595LogProvider.java view sou ... -
Google Web Toolkit (GWT) MVP Example (3)
2009-11-24 18:07 1387GreetingResponsePresenter.java ... -
Google Web Toolkit (GWT) MVP Example (2)
2009-11-24 18:03 2504GreetingPresenter.java vi ... -
Google Web Toolkit (GWT) MVP Example (1)
2009-11-24 17:49 3805本文转自:http://blog.hivedevelopmen ... -
Guice了解理解及应用
2009-11-20 11:39 1174首先,从dependency injection理解开始,咱不 ...
相关推荐
GWT(Google Web Toolkit) 是 Google 最近推出的一个开发 Ajax 应用的框架,它支持用 Java 开发和调试 Ajax 应用,本文主要介绍如何利用 GWT 进行 Ajax 的开发。 GWT特性简介 1.动态,可重用的UI组件 GWT提供的...
通过这本精巧的食谱,深入了解GWT编程世界,其中介绍了GWT Toolkit的常用配方! 它涵盖了广泛的主题,从示例应用程序和面试问题到回调功能和各种小部件。
一组Web开发工具集,包含在客户端将Java代码转为JavaScript的编译器、XML解析器、RCP 官网API、JUnit集成、国际化支持和GUI控件。
ajax例子,Google Web Toolkit 1.0.21-ajax example, Google Web Toolkit 1.0.21
GWT(Google Web Toolkit) 是 Google 最近推出的一个开发 Ajax 应用的框架,它支持用 Java 开发和调试 Ajax 应用,本文主要介绍如何利用 GWT 进行 Ajax 的开发。 Ajax技术是当前开发web应用的非常热门的技术,也是...
Google Web Toolkit Applications(GWT)入门参考资料,具有一定参考价值
google web toolkit (GWT)1.5.3,最新版本!
Google Web Toolkit参考书籍
Google Web toolkit (gwt)的介绍,可以快速进入
Using Google Web Toolkit (GWT) for Developing AJAX-Based Web Applications for the SAP NetWeaver J2EE Framework.pdf
Google Web Toolkit (GWT),可以使用 Java 编程语言编写 AJAX 前端,然后 GWT 会交叉编译到优化的 JavaScript 中,而 JavaScript 可以自动在所有主要浏览器上运行。在开发过程中,您可以用 JavaScript 按照您习惯的...
Google Web Toolkit(GWT)
面向 Java 开发人员的 Ajax 探索 Google Web Toolkit
使用 Google Web Toolkit、Apache Derby 和 Eclipse 构建 Ajax 应用程序 图文教程
Accelerated GWT: Building Enterprise Google Web Toolkit Applications
面向 Java 开发人员的 Ajax: Google Web Toolkit 入门 图文教程
Google Web Toolkit Applications(GWT)中级参考资料,具有一定参考价值
官网gwt SDK ,通过java 开发前端页面,并且自动解决页面兼容及国际化问题,以MVP为主开发模式
有了 Google Web Toolkit (GWT),可以使用 Java 编程语言编写 AJAX 前端,然后 GWT 会交叉编译到优化的 JavaScript 中,而 JavaScript 可以自动在所有主要浏览器上运行。在开发过程中,您可以用 JavaScript 按照您...