Spring security, DWR and session time out

In AJAX applications, using Spring security, handling session time out is a bit tricky. The problem is summarized here. Fortunately with DWR it is easy. DWR provides a way to handle errors, exceptions etc globally. Check  more on this here . As mentioned in the doc, you can use ‘textHtmlHandler’ to handle session time out. Here is the snippet,

dwr.engine.setTextHtmlHandler(function() {

//If the current page is secure, Spring security redirects you to login page
document.location.reload(true);
//Or you can set the document.location to your login page.
})

GWT is cool, but not complete

These observations are based upon my past 3 month’s experience with GWT. If you are new to GWT check the site here. The very idea of building your AJAX applications in Java is very enticing and GWT team has done good job of providing a way to do it using GWT. Let’s dive into things that matters to you if you want to go for GWT.

Precautions: It looks like Java and feels like Java. This picture may lure you to think that you can do everything in GWT that you can do in Java. It is not true. You need to keep in mind that you can only do things in GWT that you can do with JavaScript and HTML. You build your UI using GWT widgets. You feel at home with the API, if you are familiar with Swings. For each widget GWT generates equivalent HTML element and Java Script for processing.You should make sources of all the Java classes, you use in GWT, available to compiler. Your processing code should be Java 1.4 compatible and you have to forget about multi threads and other features that are not supported in Java Script. If you have already gone through GWT documentation, you would have known GWT provides a way to embed Java Script inside the Java code using JSNI. As I said, although you write code in Java you have to keep Java Script supported features in mind. If you are a starter, you better look into examples provided in GWT site. The documentation is adequate.

There is a huge advantage when it comes to debugging. Because it is (like) Java, you can use any of your existing Java tools for development.

Widgets: This is the area where I was really disappointed. The widgets that come with GWT are really minimum. This caused my initial resistance going towards GWT. All you get is raw widgets and they look a bit ugly (You can change the look of the widgets by injecting CSS styles). No built in data binding and validation for widgets, viewers, drag and drop etc. You need to build everything on your own. There are third party libraries available for features like drag and drop, effects, viewers etc. By default, GWT should have provided lot of UI components that any RIA framework or tool set provides. For example, like Flex,Echo 2, Ext etc. There are efforts to make situation better. Check the resource section for GWT libraries and examples.

Server communication: GWT provides two options for you client side code to communicate with server. One is using pure JSON over HTTP and, second one is using RPC. The RPC mechanism abstracts you from the nonsense of dealing with marshaling and unmarshaling of JSON. You can deal with pure Java objects. There is a caveat here, which I will discuss in next paragraph. Here again, if you want to communicate with server using SOAP XML messages or some other form of communication, you are left on your own. This is not a show stopper or something of that sort. But when you look at Flex or Open Laszlo, you desire for that in GWT.

With GWT-RPC, your code should be Java 1.4 compatible(I heard GWT team is working towards brining Java 5 compatibility to GWT). If your domain objects uses Java 5 features like generics, annotations, you can not reuse the same domain objects as value objects. Then, you need to introduce some conversion mechanism here.

Even if your code domain objects are Java 1.4 compatible, you need GWT specific XML file in your domain objects source package.

And GWT-RPC have some problems with Hibernate. If you return PersistentSet when RPC expects Set, the RPC mechanism throw error. Also there are obvious problems with Hibernate proxies, java.sql.Timestamp. There is a library called hibernate4gwt which aims to alleviate these problems.

Alternatives : If you like the approach of building your AJAX apps in Java and let the tool take care of converting it to Java Script and HTML, you may like to look at projects similar to GWT. They are

· Echo 2– Similar to GWT. The number of widgets available is more when compared to GWT. Check the demo in their site.

· WebCream– Converts Swing applications to AJAX applications. They claim, if your Swing applications do not use many custom components, they can convert it into AJAX application without any changes.

· J2S– JavaScript equivalent of SWT. They are trying to build Eclipse RCP to web.

GWT is a good way of building AJAX applications for Java developers. It is not complete framework, keep T(tool) in GWT in mind. It provides you bricks. You need to build your wire frames and house, sometimes third party libraries may help you. Nevertheless, I feel it is far better way than building your UI using Java Script(Java Script really scares me). If GWT team comes up with more rich UI components and a framework on top of them(Imagine something like JFace ported to GWT), GWT is the way to go. It is over a year since GWT is around. With Google behind we may safely expect more good things happen for GWT.

Resources

1. GWT– Official home for GWT.

2. GWT Incubator – Ideas and Widgets that may go to GWT library.

3. MyGWT – Widget library. The best I have found and they borrow some of the concepts from JFace for viewers. The default look itself is great.

4. www.onGWT.com– Tracks news on GWT and very informative. You can also find about various libraries here.

5. Roberts Hanson’s blog – Blog from the author of the book, ‘GWT in Action’. He is creator of gwt-wl(widget library) and gwt-sl(server library, which provides controllers for integrating with Spring and other server side utilities).

6. Gwanted – Helps you to use GWT in any web page, Error management etc

7. hibernate4gwt – Helps you to solve problems with GWT-RPC and Hibernate.

8. gwt-ext library – The creator of the library is Sanjiv Jivan. He ported Java Script EXT library to GWT.

9. gwt-tk library– Provides widgets like drop down panels, glass panels, various types of dialogs.

10. GWM library– GWT windows manager provides window effects for GWT applications.

11.Other– GWT related projects from Google code.

12.rocket-gwt– Widget library.