- 浏览: 110146 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
0c0c0f:
原来如此str.replaceAll("[\\x00 ...
xml中的非法字符 -
twlkyao:
谢谢,问题解决了。
xxx is not in the sudoers file解决方法 -
guanshubang:
czxvxcv[b][/b]
在eclipse中使用junit -
帅先勃:
...
Java设计模式之生产者消费者模式 -
liberD:
我昨天试了,报了很多的错误。请问,您遇到这种情况了吗?
git安装
GreetingResponsePresenter.java
01.
package
co.uk.hivedevelopment.greet.client.mvp;
02.
import
net.customware.gwt.presenter.client.EventBus;
03.
import
net.customware.gwt.presenter.client.place.Place;
04.
import
net.customware.gwt.presenter.client.place.PlaceRequest;
05.
import
net.customware.gwt.presenter.client.widget.WidgetDisplay;
06.
import
net.customware.gwt.presenter.client.widget.WidgetPresenter;
07.
import
co.uk.hivedevelopment.greet.shared.event.GreetingSentEvent;
08.
import
co.uk.hivedevelopment.greet.shared.event.GreetingSentEventHandler;
09.
import
com.allen_sauer.gwt.log.client.Log;
10.
import
com.google.gwt.event.dom.client.ClickEvent;
11.
import
com.google.gwt.event.dom.client.ClickHandler;
12.
import
com.google.gwt.event.dom.client.HasClickHandlers;
13.
import
com.google.gwt.user.client.ui.DialogBox;
14.
import
com.google.gwt.user.client.ui.HasHTML;
15.
import
com.google.gwt.user.client.ui.HasText;
16.
import
com.google.inject.Inject;
17.
public
class
GreetingResponsePresenter
extends
WidgetPresenter {
18.
public
interface
Display
extends
WidgetDisplay {
19.
HasText getTextToServer();
20.
HasHTML getServerResponse();
21.
HasClickHandlers getClose();
22.
DialogBox getDialogBox();
23.
}
24.
public
static
final
Place PLACE =
new
Place(
"GreetingResponse"
);
25.
@Inject
26.
public
GreetingResponsePresenter(
final
Display display,
final
EventBus eventBus) {
27.
super
(display, eventBus);
28.
bind();
29.
}
30.
31.
@Override
32.
protected
void
onBind() {
33.
// Add a handler to close the DialogBox
34.
display.getClose().addClickHandler(
new
ClickHandler() {
35.
public
void
onClick(
final
ClickEvent event) {
36.
display.getDialogBox().hide();
37.
// Not sure of a nice place to put these!
38.
// sendButton.setEnabled(true);
39.
// sendButton.setFocus(true);
40.
}
41.
});
42.
eventBus.addHandler(GreetingSentEvent.TYPE,
new
GreetingSentEventHandler() {
43.
@Override
44.
public
void
onGreetingSent(
final
GreetingSentEvent event) {
45.
Log.info(
"Handling GreetingSent event"
);
46.
47.
display.getTextToServer().setText(event.getName());
48.
display.getServerResponse().setHTML(event.getMessage());
49.
display.getDialogBox().show();
50.
}
51.
});
52.
}
53.
@Override
54.
protected
void
onUnbind() {
55.
// Add unbind functionality here for more complex presenters.
56.
}
57.
public
void
refreshDisplay() {
58.
// This is called when the presenter should pull the latest data
59.
// from the server, etc. In this case, there is nothing to do.
60.
}
61.
public
void
revealDisplay() {
62.
// Nothing to do. This is more useful in UI which may be buried
63.
// in a tab bar, tree, etc.
64.
}
65.
/**
66.
* Returning a place will allow this presenter to automatically trigger when
67.
* '#GreetingResponse' is passed into the browser URL.
68.
*/
69.
@Override
70.
public
Place getPlace() {
71.
return
PLACE;
72.
}
73.
@Override
74.
protected
void
onPlaceRequest(
final
PlaceRequest request) {
75.
// this is a popup
76.
}
77.
}
At this point, we're still missing some code but hopefully you should start to see the structure coming together.
Events
Since this is a simple application, we only have one event - the GreetingSent event which has a corresponding handler:
GreetingSent.java
01.
package
co.uk.hivedevelopment.greet.shared.event;
02.
import
com.google.gwt.event.shared.GwtEvent;
03.
public
class
GreetingSentEvent
extends
GwtEvent{
04.
public
static
Type TYPE =
new
Type();
05.
06.
private
final
String name;
07.
private
final
String message;
08.
09.
public
GreetingSentEvent(
final
String name,
final
String message) {
10.
this
.name = name;
11.
this
.message = message;
12.
}
13.
14.
public
String getName() {
15.
return
name;
16.
}
17.
18.
public
String getMessage() {
19.
return
message;
20.
}
21.
22.
@Override
23.
public
Type getAssociatedType() {
24.
return
TYPE;
25.
}
26.
@Override
27.
protected
void
dispatch(
final
GreetingSentEventHandler handler) {
28.
handler.onGreetingSent(
this
);
29.
}
30.
}
GreetingSentHandler.java
1.
package
co.uk.hivedevelopment.greet.shared.event;
2.
import
com.google.gwt.event.shared.EventHandler;
3.
public
interface
GreetingSentEventHandler
extends
EventHandler {
4.
void
onGreetingSent(GreetingSentEvent event);
5.
}
If you now look at the project references for the event and handler you can see where the events are fired and subsequently handled. The components are blissfully unaware of what produced the event and it just has the information that it needs to get the job done. Now imagine if you want to have another component that also reacts to this event, say to update another part of the GUI. Simple, just register another event handler - no spaghetti code.
RPC
Let's define client RPC. As mentioned earlier, we'll not be making the RPC calls directly. Instead we'll use the command pattern and let the gwt-dispatch library handle the underlying server calls. Although this is an implementation of the command pattern, it turns out that there is already a core GWT class called Command, so the authors of the gwt-dispatch library have opted to use Action instead - so "actions" are really "commands".
In our example, we'll define the Action SendGreeting which represent our server request and a SendGreetingResult class to encapsulate the server response:
SendGreeting.java
01.
package
co.uk.hivedevelopment.greet.shared.rpc;
02.
import
net.customware.gwt.dispatch.shared.Action;
03.
public
class
SendGreeting
implements
Action {
04.
private
static
final
long
serialVersionUID = 5804421607858017477L;
05.
private
String name;
06.
@SuppressWarnings
(
"unused"
)
07.
private
SendGreeting() {
08.
}
09.
public
SendGreeting(
final
String name) {
10.
this
.name = name;
11.
}
12.
public
String getName() {
13.
return
name;
14.
}
15.
}
SendGreetingResult.java
01.
package
co.uk.hivedevelopment.greet.shared.rpc;
02.
import
net.customware.gwt.dispatch.shared.Result;
03.
public
class
SendGreetingResult
implements
Result {
04.
private
static
final
long
serialVersionUID = 7917449246674223581L;
05.
private
String name;
06.
private
String message;
07.
public
SendGreetingResult(
final
String name,
final
String message) {
08.
this
.name = name;
09.
this
.message = message;
10.
}
11.
@SuppressWarnings
(
"unused"
)
12.
private
SendGreetingResult() {
13.
}
14.
public
String getName() {
15.
return
name;
16.
}
17.
public
String getMessage() {
18.
return
message;
19.
}
20.
}
发表评论
-
git安装
2011-07-05 17:39 1902linux 安装git 2011-01-06 10:01 ... -
myeclipse8.0GA CDkey
2010-05-24 13:33 1165Subscriber:MaYong Subscript ... -
svn无法更新,问题解决方法
2010-03-29 10:23 11158Working copy’**’locked. Please ... -
xml中的非法字符
2010-03-10 18:06 13855今使用Jdom生成xml文件的时候,总是出现0x0,0x8为非 ... -
mysql 添加访问权限
2010-03-10 15:11 1564记录下来,省得以后找不到。 shell>mysq ... -
xxx is not in the sudoers file解决方法
2010-01-11 11:19 5052用sudo时提示"xxx is not in t ... -
Session ID and Cookie
2010-01-08 14:59 3191具体来说cookie机制采用 ... -
Google Web Toolkit (GWT) MVP Example (5)
2009-11-24 18:13 1591LogProvider.java view sou ... -
Google Web Toolkit (GWT) MVP Example (4)
2009-11-24 18:10 1927At this point, the client code ... -
Google Web Toolkit (GWT) MVP Example (2)
2009-11-24 18:03 2501GreetingPresenter.java vi ... -
Google Web Toolkit (GWT) MVP Example (1)
2009-11-24 17:49 3801本文转自:http://blog.hivedevelopmen ... -
Guice了解理解及应用
2009-11-20 11:39 1172首先,从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为主开发模式
GWT学习资料