How to Use Google Web Toolkit with Struts and JSP

46 views
Skip to first unread message

vijay...@gmail.com

unread,
Jul 20, 2006, 3:46:26 PM7/20/06
to Google Web Toolkit
Hi All

I want to know the Framwork which is used to integrate Google Web
Toolkit with Struts and JSP. Please help me out.

Vijay

IamRobe...@gmail.com

unread,
Jul 21, 2006, 12:35:57 PM7/21/06
to Google Web Toolkit
Specifically what type of integration are you looking for? What do you
want GWT+Struts to do for you?

I have been thinking about what GWT+Struts actually means, and what
tools would be useful, but I have been drawing a blank. If you can
give me some example, perhaps some tools will find their way to the
GWT-WL.

Rob
http://gwt-widget.sourceforge.net

vijay...@gmail.com

unread,
Jul 21, 2006, 2:01:46 PM7/21/06
to Google Web Toolkit
Hi rob

I am very new with Google Web Toolkit . Iwant use it in my application
based on MVC struys framwork..how can be this toolkit will be
benificial to me.

Vijay

IamRobe...@gmail.com

unread,
Jul 21, 2006, 2:09:46 PM7/21/06
to Google Web Toolkit
That is actually what I am asking. What do you need it to do? How do
you need it to integrate?

If what you want is to be able to use the TabPanel, some Buttons, and
handle some events, then you just use it like you would use it with an
HTML page.

If you are interested in RPC, you probably wouldn't want a tight
integration because an Action doesn't handle object serialization like
a RemoteServlet does.

To ask the question again, what would you want it to be able to do?

Rob

Joachim

unread,
Jul 22, 2006, 4:29:55 PM7/22/06
to Google Web Toolkit
Hi Robert,

> If what you want is to be able to use the TabPanel, some Buttons, and
> handle some events, then you just use it like you would use it with an
> HTML page.

Could you tell us more about the "simple" case with "not much"
integration ?

Because I don't find it obvious how to pass GWT-variables to Struts
Forms.

Thanks,
Joachim

Robert Hanson

unread,
Jul 22, 2006, 5:09:29 PM7/22/06
to Google-We...@googlegroups.com
> 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

Joachim

unread,
Jul 23, 2006, 8:06:56 AM7/23/06
to Google Web Toolkit

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 :

> ------=_Part_147248_8011402.1153602569624
> Content-Type: text/html; charset=ISO-8859-1
> X-Google-AttachSize: 5555
>
> &gt; Because I don't find it obvious how to pass<br>&gt; GWT-variables to Struts Forms.<br><br>I guess that is what I am getting at... you wouldn't pass anything to Struts.&nbsp; Once you deliver that first HTML page with GWT code in it, the page would never refresh.&nbsp; The HTML page would never change.
> <br><br>...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.&nbsp; 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.
> <br><br>Or to summarize, once the first page is served, the only data passed between the server and the client are Java objects.<br><br>But again, it all depends on what you need to do.&nbsp; A friend of mine is looking into using GWT for an application solution, who is also a big fan of Struts.&nbsp; 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.&nbsp; I provided a solution that looks like this...
> <br><br>// create a tabbed panel, and add it to the page<br>TabPanel tp = new TabPanel();<br>RootPanel.get().add(tp);<br><br>// create two frames, pointing to Struts actions<br>Frame frame1 = new Frame(&quot;/frame1Action.do&quot;);
> <br>Frame frame2 = new Frame(&quot;/frame2Action.do&quot;);<br>
> <br>// add the frames to the panel<br>tp.add(frame1);<br>tp.add(frame2);<br>
> <br>He had a follow-up question asking how he would pass variables to the Struts actions.&nbsp; My response was to pass them in the URL.<br><br>frame1.setUrl(&quot;/frame1Action.do?foo=1&amp;bar=2&quot;);<br><br>In his application the contents of the Frames are Struts actions, and are not GWT enabled.&nbsp; What is GWT enabled is the container that holds the frames.
> <br><br>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.&nbsp; Here is an example: <a href="http://gwt-widget.sourceforge.net/demo/calc/index.html">
> http://gwt-widget.sourceforge.net/demo/calc/index.html</a>.<br><br>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.&nbsp; This is an example of enhancing the page with no need for server-side integration.
> <br><br>So the answer is, it depends.&nbsp; It depends on the specific problem.<br><br>There is no requirement that the whole page use GWT widgets.&nbsp; 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.
> <br><br>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.<br><br>1. Don't tie your business logic to the Struts action.<br>
> 2. Create business logic components that can be used by both Struts actions and GWT servlets.<br>3. Use the appropriate tool, either Struts action or GWT servlet depending on what you are doing.<br><br>Here is an example.&nbsp; Lets say that you have a form for gathering sign-up information.&nbsp; The initial form page would probably be a plain HTML page served to the user.&nbsp; This page would have GWT code in it to allow for client-side validation of the entries.
> <br><br>(form entry) The user enters their name into the first field, and moves to the second field.&nbsp; The client-side GWT code immediately sends the value of the first field to the server for validation.&nbsp; The idea being that we want to make the sign-up process painless, and point our entry errors as soon as possible.
> <br><br>(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.&nbsp; While the user is filling out the form we only ever call GWT servlets.
> <br><br>(form submission) Once the user is entering data they submit the form to the server for processing.&nbsp; In this example this submission it to an ordinary Struts action, and the data is submitted in the normal way, using an HTML form.
> <br><br>(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.&nbsp; In this case the Struts action calls the same business module that the GWT servlet used.
> <br><br>In this example there is integration between Struts and GWT, but only where it makes sense to do so to solve the given problem.<br><br>I don't know if that helps, but maybe you can see what I am getting at.&nbsp; If you have a specific problem that needs a solution I would be interested in hearing what it is.
> <br><br>Rob<br><br><br><div><span class="gmail_quote">On 7/22/06, <b class="gmail_sendername">Joachim</b> &lt;<a href="mailto:Trista...@gmail.com">Trista...@gmail.com</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
> <br>Hi Robert,<br><br>&gt; If what you want is to be able to use the TabPanel, some Buttons, and<br>&gt; handle some events, then you just use it like you would use it with an<br>&gt; HTML page.<br><br>Could you tell us more about the &quot;simple&quot; case with &quot;not much&quot;
> <br>integration ?<br><br>Because I don't find it obvious how to pass GWT-variables to Struts<br>Forms.<br><br>Thanks,<br>Joachim<br></blockquote></div><br>
>
> ------=_Part_147248_8011402.1153602569624--

Reply all
Reply to author
Forward
0 new messages