Share / Save this...

Share/Bookmark

2010-06-27

GWT + Struts 1.x + Netbeans Tutorial (Part 5)




<c:choose>
     <c:when test="${user.likes}"
          Share this with your friends
     </c:when>
     <c:otherwise>  
          Send me feedback.
     </c:otherwise>
<:choose>
oDesk Certified Java Developer

Part 5: Add GWT support to a Struts 1.x application.

In the previous parts we've configured our environment to work with both GWT and Struts. This part is as short as the last one, we're going to add GWT support to our "existing" Struts application (which happens to be a new Struts application too) and also make the GWT module available to our welcome page.

To add GWT support to our Struts project we need to right-click the project's name in the project tab in Netbeans, and select "Properties". In the properties section select "Frameworks" we need to click the "Add" button next to the "Used Frameworks" list and select Google Web Toolkit from the available frameworks list. Especify the location of the GWT SDK and the GWT Module name. Things get a lot easier if you expecify the GWT Module name  to be the same as your MessageResource location and adding a dot and the module name in this way: ".<the-module-name-here>" at the end.
In our example i chose com.example.strutsgwt.Welcome.

After adding the GWT framework to our project, our structure changes to accommodate to the new classes, we get a "client" package with an EntryPoint subclass inside, a <the-module-name-here>.gwt.xml module file and a welcome file. We defined our Struts message resources file location to be com.example.strutsgwt.MessageResource therefore it can be found inside the com.example.strutsgwt package along with the Welcome.gwt.xml file. The gwt.xml file has the name of the module, which in our example it would translate to Welcome.gwt.xml.

Let's get to the important part, how to add the generated JavaScript to the pages we want. In the welcomeGWT.html file you find along with the welcome files and JSPs there are 2 important lines you need to copy. First there's a meta tag with a property GWT understands and then there's the usual script tag with the location of the EntryPoint. We are going to copy those 2 lines from the welcomeGWT.html file to the welcomeStruts.jsp file. I placed the 2 lines inside the head section of the JSP file.

You can now compile everything and test it. GWT compiles your Java code into JavaScript code so the compilation is a bit long and you might want to get used to this coding philosophy: use Hosted Mode for GWT testing, make changes and refresh the page while using hosted mode. I use Hosted Mode for the client (GWT) and i like compiling everything every now and then to check the whole project. Find your own pace.



If you have any suggestions, ideas for full blown system integration (sb) or comments, leave a message below.

I would appreciate if you could Share this with your friends



No comments:

Post a Comment

Hits