Archive

Archive for November, 2008

Hibernate, Spring and GWT for GWT 1.5

November 26th, 2008 admin No comments

A few people have now let me know (quite rightly) that the Hibernate, Spring and GWT tutorial is now out of date after the release of GWT 1.5

I believe the application should still work but….
As a result here is a summary of the changes you need to make to make the application to make it 1.5 compatible.

JAR Files

Firstly update the GWT jar files within the WEB-INF/lib folder. Make sure you update the gwt-servlet jar as well this MUST be the GWT 1.5 gwt-servlet.jar!

Compile, Launch and Shell Scripts

The compile launch and shell scripts should all point at your new GWT 1.5 location

@gwt.typeArgs Annotations

Although this only causes warnings you should remove all the @gwt.typeArgs annotations completely from your project. With GWT 1.5 you can use strongly typed sets such List<Object>

@RemoteServiceRelativePath and RPC

GWT 1.5 has made it easier to call and define RPC services. In my example the TeacherService should now be defined as:

package com.company.client.rpc;
 
import java.util.List;
import com.company.client.dto.PupilDTO;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
 
@RemoteServiceRelativePath("teachers")
public interface TeacherService extends RemoteService
{
    public List<PupilDTO> getPupils(Integer teacherId);
}

Notice RemoteServiceRelativePath defintion that is our path.

You can then call the service much simpler:

TeacherServiceAsync teacherService = (TeacherServiceAsync) GWT.create(TeacherService.class);
teacherService.getPupils(teacherId, new AsyncCallback<List<PupilDTO>>()
{
    public void onFailure(Throwable caught)
    {
        // TODO Auto-generated method stub
    }
 
    public void onSuccess(List<PupilDTO> result)
    { 
        pupils = result;
        notifyObservers();
    }
 
});

I have also updated the project and this can be downloaded as a zip file.