GWT to EJB Bridging

August 1, 2007

I recently figured out that I could save myself a lot of hassle by implementing my GWT service/servlet in a bean. Once it’s a bean, all its methods are automatically wrapped in a transaction, which keeps my code really clean. Previously I didn’t think this was possible without having a ton of delegate methods in the servlet. However, I’ve discovered that I can just have my servlet dispatch client requests directly to a bean by overriding processCall(). Read the rest of this entry »


Tip: Fast Publish with Eclipse GWT Plugin

July 28, 2007

I previously linked to this GWT plugin for eclipse from eclipseguru.org.

It’s great in that I can easily run my project in the GWT browser, use the debugger, hit refresh to reload my classes, and it automatically compiles and deploys everything when I deploy the server.

One useful trick I’ve come up with is to create a link folder in my GWT project (called deploy.gwt) which points at the already-deployed web app folder. This means that I can deploy my GWT to the webserver quickly by pointing GWT at that link (Project > Properties > GWT Deployment > Output folder = “deploy.gwt”) and using the “GWT Tools > Compile and Publish” context menu item on the project to compile and publish directly into the container. Now I can test in a non-hosted browser after only a few seconds, instead of waiting a minute for a standard glassfish deployment. It also updates the css and images, but not servlets. It is a huge time saver when tweaking CSS and images.


GWT using a Stateful EJB in the HTTP Session via a Servlet

July 22, 2007

I’m happy to have finally got my stateful session bean stored in the client session and accessed by a GWT client. (Yes, I’ve dropped facelets in favor of GWT).

The stateful session bean code is pretty simple, here is the class declaration with the annotation.

@Stateful
public class MyAppSessionImpl implements MyAppSession
{ ... }

The MyAppSession interface includes the doLogin() and isLoggedIn() methods, which are implemented by MyAppSessionImpl. It has the @Remote attribute.

I expose these methods using a GWT-style servlet to handle the RPC calls (see code below, it’s a full listing). The servlet has to provide an interface that uses only simple serializable types that are known to the GWT client code; obviously, this won’t include my database entities because they use annotations and are in a different Jar. Thus, all the database objects have to repackaged into a more GWT-digestable form for the client.

The MyAppSession interface will provide a user’s view of the database. It is backed by a the Dao and shares objects with it. The servlet has no transactions surrounding its methods, so any database entity returned by the session interface has to be considered read-only, or modified only through calls to the session interface. Database updates will probably be done by passing object IDs to the session interface methods along with new values/states to store for that object, which will make the session interface generally usable across different types of RPC.

This session is stored in the Servlet’s HTTP Session for the client; a new one is created if there isn’t currently one, or if the old one expired or was deleted.

Here’s the sample code, I hope you all find it helpful: Read the rest of this entry »