Skip to main content

Adding a custom GWT module in a Roo-project

So I started looking into Roo the other day. Seems like a nice tool (once it matures a little more). Anyway - I wanted to create a custom module in addition to the two being generated when adding GWT-support to the project. Not as easy as I thought, mainly because I hadn't seen the Url Rewrite Filter before. I ended up with a 404, no matter what I did, and couldn't figure out why. Frustration!

After reading up on the url rewrite stuff, I was ready to give it another try. Let's create a module called Application, based on the standard sample application you'll get using the GWT wizard in Eclipse. First of all, create the Roo project using the following instructions:

project --topLevelPackage com.technowobble
persistence setup --provider HIBERNATE --database HYPERSONIC_IN_MEMORY
entity --class com.technowobble.domain.MyEntity
gwt setup

(The "gwt setup" setup command generates some code that will not compile unless there's a persistence setup and at least one entity.)

Next, create the Application.gwt.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.0.1//EN" "http://google-web-toolkit.googlecode.com/svn/tags/2.0.1/distro-source/core/src/gwt-module.dtd">
<module rename-to="application">
  <inherits name="com.google.gwt.user.User" />
  <inherits name="com.google.gwt.user.theme.standard.Standard" />

  <inherits name="com.technowobble.gwt.ApplicationCommon" />

  <source path="client" />
  <source path='shared'/>
  
  <entry-point
    class="com.technowobble.gwt.client.Application" />
</module>

We also need to add the actual Application-class (Application.java) and the service classes (GreetingService.java, GreetingServiceAsync.java, GreetingServiceImpl.java and FieldVerifier) from the Eclipse GWT sample application. While we're at it, put the Application.html and Application.css into the src/main/webapp folder.

Of course, the service servlet needs to be added to web.xml:

<servlet>
    <servlet-name>greetServlet</servlet-name>
    <servlet-class>com.technowobble.gwt.server.GreetingServiceImpl</servlet-class>
  </servlet>
  
  <servlet-mapping>
    <servlet-name>greetServlet</servlet-name>
    <url-pattern>/application/greet</url-pattern>
  </servlet-mapping>

Before we can access the new module we need to add the following rules to urlrewrite.xml:

<rule enabled="true">
        <from casesensitive="false">/application/**</from>
        <to last="true" type="forward">/application/$1</to>
    </rule>
    <rule enabled="true">
        <from casesensitive="false">/Application.html</from>
        <to last="true" type="forward">/Application.html</to>
    </rule>    

The html file contains a reference to the stylesheet, which needs to be updated due to the Url Rewrite Filter - just change the href to href="static/Application.css".

That's it. Of course, an interesting exercise would be to combine this with the use of the DispatcherServlet and a Spring/GWT-integration controller like the GwtRpcController being used in my blog entry about Spring Security and GWT

You can find the full source here.

Comments

Post a Comment

Popular posts from this blog

Getting filters to play nicely with Spring

After having some struggle with getting filters to integrate well with my Spring context, I decided to write down a small tutorial for it...

To begin with, filters are defined in web.xml and are therefore not automatically part of the Spring application context, which is normally set up using the DispatcherServlet. A good way to abstract away all this is to use the DelegatingFilterProxy, which is a Spring utility class that acts as a filter, but will delegate the doFilter-method to a Spring-managed bean - normally a class extending GenericFilterBean.

As a filter is defined in web.xml and looks for the bean defined in the Spring context in applicationContext.xml, it's not really the set up that I want. Filters are part of a web application and should have access to what's usually defined in webmvc-config.xml, as part of the DispatcherServlet set up. To be able to use, e.g. request scoped beans in applicationContext.xml, you need to defined them as proxied objects in order to have…

GWT and Spring Security

Update! - Based on the post below, and my other post regarding Spring Security and OpenID, I have added Open-ID support to the sample application below. For those interested, here's the write-up of changes.



I've spent quite some time digging into ways of integrating GWT and Spring Security. It all started by reading the following post in the GWT Forum - Best practices/ideas for GWT with Spring Security (or equivalent), and then checking out this blog - GWT and Spring Security. To make matters worse, I started reading Security for GWT Applications and specifically about the "Cross-Site Request Forging"-attacks.

Now, what could I do about it?

Well, starting by setting up my own project (Maven-based) with all updated dependencies (GWT 2.0.3 etc) and started reading the Spring Security Reference Documentation (puh!).

Instead of See Wah Cheng's approach of implementing a custom authentication service, I decided to rely on standard namespace configuration (with some ex…

Using SmartGWT with Jersey RESTful backend on Spring Roo

I decided to give SmartGWT a run, and specifically the RestDataSource functionality using Jersey. To make things easier, I'm using Spring Roo to set up my project and scaffold much of the boilerplate code, configurations etc.

My approach is to have my domain objects exposed as RESTful web services and create a matching SmartGWT DataSource in order to show them in a GUI.

Let's get started, shall we?

First of all, you'll need Spring Roo (unless you just download the project source code and want to run it directly). I'm using the following Roo script to start things off:

project --topLevelPackage com.technowobble persistence setup --provider HIBERNATE --database HYPERSONIC_IN_MEMORY entity --class ~.domain.Message field string --fieldName value controller class --class ~.ws.MessageResource --preferredMapping rest dependency add --groupId com.sun.jersey --artifactId jersey-server --version 1.3 dependency add --groupId com.sun.jersey.contribs --artifactId jersey-spring --…