gwt 学习总结一下。
2006-10-08 21:18
639 查看
现在天下大乱啊,到外都是要用ajax,
为了加入这一大军中,自然我也是去学习了一下ajax,
对了烦又乱,又不好调度的javascript我自然没有太多好感了,
可是又不可能不学啊。
现在也是要找工作 的时候了。
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
学啊学啊,
上google 实验室看了看,看到了google web toolkit,
这下可把我乐坏了。
凭着我的这点英语水平,还好看看文档是够的。(之前我也讲过我鄱译过几万字的英文nutch 文档,)
。。。。。。。。。。。。。。。。。。。。。。。。
下了GWT ,开始看develop guide
。。。。。。。。。。。
主要是两个方面,client 和RPC ,
client 是用在brouwer上的viewr,和java里的awt相差无几,如果你对awt熟的话,就直接用就可以了。
另一个是RPC,
两个接口,一个实现完成 一个module作为一个server.
在名字的命名上如下
public interface MyService extends RemoteService ...{
public String myMethod(String s);
}
interface MyServiceAsync ...{
public void myMethod(String s, AsyncCallback callback);
}
public class MyServiceImpl extends RemoteServiceServlet implements
MyService ...{
public String myMethod(String s) ...{
// Do something interesting with 's' here on the server.
return s;
}
}
如果就是用gwt 和hibernate 来做一个小东西的话,这样你就可以用了。
以下是rpc 的uml 图,懂的话看一下就知道 了。
为何要这个异步接口呢?
因为 ajax 的原理所然,这是一个brouwer和sever的一个中间层,这样brouwer就不用刷新了。
一个大问题是gwtt 和struts 的itegration,虽然有几个文章讲了一下,但是深度的结合使用还不是很清楚,今天先写到这里吧。
以下这个回复是在google gwt 论坛上看到 的,比较实用。
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
> Because I don't find it obvious how to pass
> GWT-variables to Struts Forms.
I guess that is what I am getting at... you wouldn't pass anything to
Struts. Once you deliver that first HTML page with GWT code in it, the page
would never refresh. The HTML page would never change.
...Instead the page would pass the form data as a Java bean, which would
then be validated/stored on the server, and the server would return a Java
value. The return value might be a boolean to indicate success, or an error
object to indicate failure, or some other Java object that holds return
data.
Or to summarize, once the first page is served, the only data passed between
the server and the client are Java objects.
But again, it all depends on what you need to do. A friend of mine is
looking into using GWT for an application solution, who is also a big fan of
Struts. His specific problem was that he wanted a tabbed panel, and each
pane would be a different web page, and I assume that means a Struts
action. I provided a solution that looks like this...
// create a tabbed panel, and add it to the page
TabPanel tp = new TabPanel();
RootPanel.get().add(tp);
// create two frames, pointing to Struts actions
Frame frame1 = new Frame("/frame1Action.do");
Frame frame2 = new Frame("/frame2Action.do");
// add the frames to the panel
tp.add(frame1);
tp.add(frame2);
He had a follow-up question asking how he would pass variables to the Struts
actions. My response was to pass them in the URL.
frame1.setUrl("/frame1Action.do?foo=1&bar=2");
In his application the contents of the Frames are Struts actions, and are
not GWT enabled. What is GWT enabled is the container that holds the
frames.
Another situation might be that you want to provide the user with a
calculator (or calendar, color picker, etc) tool to help them fill in a form
field. Here is an example:
http://gwt-widget.sourceforge.net/demo/calc/index.html.
In the example the result of the calculation is placed in text box, which
could then be submitted to a Struts action in the normal way. This is an
example of enhancing the page with no need for server-side integration.
So the answer is, it depends. It depends on the specific problem.
There is no requirement that the whole page use GWT widgets. So you could
use a single calulator tool widget or a a few Frame widgets, yet leave the
reast of the application the way you normally would.
I don't know if I am answering the question or just babeling at this point,
but I do have a recommendation for server-side integration with Struts.
1. Don't tie your business logic to the Struts action.
2. Create business logic components that can be used by both Struts actions
and GWT servlets.
3. Use the appropriate tool, either Struts action or GWT servlet depending
on what you are doing.
Here is an example. Lets say that you have a form for gathering sign-up
information. The initial form page would probably be a plain HTML page
served to the user. This page would have GWT code in it to allow for
client-side validation of the entries.
(form entry) The user enters their name into the first field, and moves to
the second field. The client-side GWT code immediately sends the value of
the first field to the server for validation. The idea being that we want
to make the sign-up process painless, and point our entry errors as soon as
possible.
(client-side validation) The server call is done through a GWT servlet,
which then passes the value to some business module, and returns the result
to the browser. While the user is filling out the form we only ever call
GWT servlets.
(form submission) Once the user is entering data they submit the form to the
server for processing. In this example this submission it to an ordinary
Struts action, and the data is submitted in the normal way, using an HTML
form.
(server-side validation) The Struts action still needs to validate the entry
because it isn't a great idea to rely on only client-side validation. In
this case the Struts action calls the same business module that the GWT
servlet used.
In this example there is integration between Struts and GWT, but only where
it makes sense to do so to solve the given problem.
I don't know if that helps, but maybe you can see what I am getting at. If
you have a specific problem that needs a solution I would be interested in
hearing what it is.
Rob
On 7/22/06, Joachim <Tristan.Ro...@gmail.com> wrote:
- Hide quoted text -
- Show quoted text -
Thanks for your explanations.
My specific problem was about "form submission", and submitting GWT
generated values to the server using a simple POST to an action, and
not RPC, but I found the answer in your FormPanel :
/**
* Adds a widget to the underlying panel and sets the "name"
* attribute. This will allow the value of the form field to
* be passed to the server when the form is submitted.
*
* @param field the widget to add to the form
* @param name the form field name
* @return false if widget can not be added
*/
public boolean addField (Widget field, String name)
{
<b> DOM.setAttribute(field.getElement(), "name", name); </b>
return add(field);
}
Robert Hanson a écrit :
为了加入这一大军中,自然我也是去学习了一下ajax,
对了烦又乱,又不好调度的javascript我自然没有太多好感了,
可是又不可能不学啊。
现在也是要找工作 的时候了。
。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
学啊学啊,
上google 实验室看了看,看到了google web toolkit,
这下可把我乐坏了。
凭着我的这点英语水平,还好看看文档是够的。(之前我也讲过我鄱译过几万字的英文nutch 文档,)
。。。。。。。。。。。。。。。。。。。。。。。。
下了GWT ,开始看develop guide
。。。。。。。。。。。
主要是两个方面,client 和RPC ,
client 是用在brouwer上的viewr,和java里的awt相差无几,如果你对awt熟的话,就直接用就可以了。
另一个是RPC,
两个接口,一个实现完成 一个module作为一个server.
在名字的命名上如下
public interface MyService extends RemoteService ...{
public String myMethod(String s);
}
interface MyServiceAsync ...{
public void myMethod(String s, AsyncCallback callback);
}
public class MyServiceImpl extends RemoteServiceServlet implements
MyService ...{
public String myMethod(String s) ...{
// Do something interesting with 's' here on the server.
return s;
}
}
如果就是用gwt 和hibernate 来做一个小东西的话,这样你就可以用了。
以下是rpc 的uml 图,懂的话看一下就知道 了。
为何要这个异步接口呢?
因为 ajax 的原理所然,这是一个brouwer和sever的一个中间层,这样brouwer就不用刷新了。
一个大问题是gwtt 和struts 的itegration,虽然有几个文章讲了一下,但是深度的结合使用还不是很清楚,今天先写到这里吧。
以下这个回复是在google gwt 论坛上看到 的,比较实用。
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
> Because I don't find it obvious how to pass
> GWT-variables to Struts Forms.
I guess that is what I am getting at... you wouldn't pass anything to
Struts. Once you deliver that first HTML page with GWT code in it, the page
would never refresh. The HTML page would never change.
...Instead the page would pass the form data as a Java bean, which would
then be validated/stored on the server, and the server would return a Java
value. The return value might be a boolean to indicate success, or an error
object to indicate failure, or some other Java object that holds return
data.
Or to summarize, once the first page is served, the only data passed between
the server and the client are Java objects.
But again, it all depends on what you need to do. A friend of mine is
looking into using GWT for an application solution, who is also a big fan of
Struts. His specific problem was that he wanted a tabbed panel, and each
pane would be a different web page, and I assume that means a Struts
action. I provided a solution that looks like this...
// create a tabbed panel, and add it to the page
TabPanel tp = new TabPanel();
RootPanel.get().add(tp);
// create two frames, pointing to Struts actions
Frame frame1 = new Frame("/frame1Action.do");
Frame frame2 = new Frame("/frame2Action.do");
// add the frames to the panel
tp.add(frame1);
tp.add(frame2);
He had a follow-up question asking how he would pass variables to the Struts
actions. My response was to pass them in the URL.
frame1.setUrl("/frame1Action.do?foo=1&bar=2");
In his application the contents of the Frames are Struts actions, and are
not GWT enabled. What is GWT enabled is the container that holds the
frames.
Another situation might be that you want to provide the user with a
calculator (or calendar, color picker, etc) tool to help them fill in a form
field. Here is an example:
http://gwt-widget.sourceforge.net/demo/calc/index.html.
In the example the result of the calculation is placed in text box, which
could then be submitted to a Struts action in the normal way. This is an
example of enhancing the page with no need for server-side integration.
So the answer is, it depends. It depends on the specific problem.
There is no requirement that the whole page use GWT widgets. So you could
use a single calulator tool widget or a a few Frame widgets, yet leave the
reast of the application the way you normally would.
I don't know if I am answering the question or just babeling at this point,
but I do have a recommendation for server-side integration with Struts.
1. Don't tie your business logic to the Struts action.
2. Create business logic components that can be used by both Struts actions
and GWT servlets.
3. Use the appropriate tool, either Struts action or GWT servlet depending
on what you are doing.
Here is an example. Lets say that you have a form for gathering sign-up
information. The initial form page would probably be a plain HTML page
served to the user. This page would have GWT code in it to allow for
client-side validation of the entries.
(form entry) The user enters their name into the first field, and moves to
the second field. The client-side GWT code immediately sends the value of
the first field to the server for validation. The idea being that we want
to make the sign-up process painless, and point our entry errors as soon as
possible.
(client-side validation) The server call is done through a GWT servlet,
which then passes the value to some business module, and returns the result
to the browser. While the user is filling out the form we only ever call
GWT servlets.
(form submission) Once the user is entering data they submit the form to the
server for processing. In this example this submission it to an ordinary
Struts action, and the data is submitted in the normal way, using an HTML
form.
(server-side validation) The Struts action still needs to validate the entry
because it isn't a great idea to rely on only client-side validation. In
this case the Struts action calls the same business module that the GWT
servlet used.
In this example there is integration between Struts and GWT, but only where
it makes sense to do so to solve the given problem.
I don't know if that helps, but maybe you can see what I am getting at. If
you have a specific problem that needs a solution I would be interested in
hearing what it is.
Rob
On 7/22/06, Joachim <Tristan.Ro...@gmail.com> wrote:
- Hide quoted text -
- Show quoted text -
Thanks for your explanations.
My specific problem was about "form submission", and submitting GWT
generated values to the server using a simple POST to an action, and
not RPC, but I found the answer in your FormPanel :
/**
* Adds a widget to the underlying panel and sets the "name"
* attribute. This will allow the value of the form field to
* be passed to the server when the form is submitted.
*
* @param field the widget to add to the form
* @param name the form field name
* @return false if widget can not be added
*/
public boolean addField (Widget field, String name)
{
<b> DOM.setAttribute(field.getElement(), "name", name); </b>
return add(field);
}
Robert Hanson a écrit :
相关文章推荐
- 今天开始每天写点技术博客 总结一下每个阶段的学习
- 初学习cocos2d小结(感冒了,几行代码都记不住...稍微复杂一点的动作序列看不下去,还是总结一下这两天看的东西)
- 总结一下 我接触的(学习的)那些项目
- 总结一下学习vb串口通信的初期果实
- 对之前的学习小小的总结一下吧
- 2011.7.20-总结一下近来学习过程中的波折
- Oracle SQL优化 总结(很全面)一起来学习一下!
- opencv 学习第四天 学习opencv(中文版) 总结一下opencv的图像视频的简单应用
- ci框架学习告一段落,总结一下
- 总结一下自己学习语言的经验(给初学者)
- 总结一下自己学习过的语言
- 双十一了,总结一下前端学习收获及感触
- 总结一下这几天学习matlab学到的东西
- GWT 学习总结
- 这一次不写什么知识博客,就遇到的学习过程中的问题简要概述一下,算是给自己做个归纳总结吧
- 总结一下学习android开发的网站
- 阶段总结:大概总结一下项目中学习的东西
- 今天初步学习了一下Git版本控制,总结一下,后面加下用Git下载android源代码
- 总结一下前面学习Linux的结果
- 今天初步学习了一下Git版本控制,总结一下,后面加下用Git下载android源代码