Friday, January 11, 2008

Hello Seam

A note on getting a ‘hello world’ reverse engineered application up and running in jboss seam

For this test I am moving two applications to seam. The first is an existing Ruby on Rails application that I’m using as a reference and will be replicating/improving the RoR functionality. The second is a bare bones web 2.0 application for which I have only recently completed the table design and for which I have a minimal set of use cases. I plan to use this as a substrate for building workflow-based/“Web 2.0 enabled” applications in a number of areas including drug discovery

In preparation, I thought I’d take an infrastructure upgrade move to Leopard and Eclipse/Europa (+ for reasons that will be apparent Netbeans 6.0). This may not have been the best idea since I encountered some eclipse/Leopard incompatibilities that were eventually resolved using the technique described here.

The first step was to install jboss, seam (I initially went with the 1.2.1 GA version since the 2.0.0 GA had too many 0’s in it for me to be comfortable) and run the demos -- this was a very enjoyable process. The installation was easy and the demos were polished.

The next step was to begin reverse engineering. With Eclipse the best result was had by first using ‘seam new-project’ to create a bare project and then import the project into eclipse (using the file->new->project as recommended). I then performed a ‘seam generate-entities’ to get all the hibernate code in place and then do a refresh of the files. This was advantageous since it allowed me to disambiguate Eclipse project import problems (which I didn’t have) from the Hibernate mapping problems (which I did have).

In eclipse the only way I could find to get the project to run on the jboss app server was to right click->’jboss tools’->’add struts capabilities’ and then add it in from the project side right-click->’run as’->’open run dialog’. There’s probably some other way to do this but I couldn’t find it quickly.

I tried to open the project in NetBeans since the seam doc indicated that you could ‘just’ open the project up in NetBeans without any special actions. This was true, but NetBeans just did not appear to understand the file layout of the 1.2.1 seam-gen project, so I dropped that path (at least until I started using seam 2.0).

I did have some problems getting the reverse engineered project to run. After a bit (maybe more) of investigation I determined that the problems revolved around the fact that both projects had blobs (one has blobs of different sizes) going against a mysql back end.

Seam structures the project in such a way that the first page won’t come up unless hibernate can successfully map the database. The default hibernate mysql/blob mapping is ‘tinyblob’ which didn’t match my applications’ blob datatypes of blob and mediumblob. In addition, Hibernate won’t take the mysql data types and it is necessary to specify the appropriate lengths when I did this everything came up fine.

I have to admit that I was a bit thrown off by the ‘first page error’ since I didn’t expect that mapping to be invoked until I started to hit those pages. This might stem from the fact that there is a navigation bar on the top of the first page that takes you to pages and map to the db, or might be standard Hibernate behavior, I have to admit that I’m not familiar enough with Hibernate to be sure.

In any case, I was up and running and started performing some minimal customization.

Seam’s default behavior for displaying blobs is to show a hex string of the first few bytes - -not a bad default as it allows you to see that it is accessing binary data and the data is different for each item. However it’s not the final behavior that I wanted.

When I tried to add some images to the pages e.g., .
I ran into issues where there were warnings of the types
WARN [HtmlRenderKitImpl] Unsupported component-family/renderer-type: org.jboss.seam.ui.UIGraphicImage/javax.faces.Image
This appeared to be a known bug in seam 1.2 that was fixed in 1.3 -- but as near as I can tell 2.0 was release which followed 1.2.

Upgrading to 2.0 (including the attendant jboss upgrade) solved this issue but broke some of the Eclipse tools, specifically the jboss tools HTML editor was unable to find any of the @Name references(I’ve seen this noted on some of the jboss forums, so I’m not alone on this).

Since I hate to go forward with an IDE showing me a ton of warnings I decided to look at Netbeans since the 2.0 version of seam has different file structure from seam 1.x. Happily, this has made the file structure much more NetBeans friendly.

I think the only thing I had to change to get it working in NetBeans was to set the deploy project to ‘restart’. I’m now up and running and in the process of modifying things work work as I want.

One side note: I find that I’m liking NetBeans more than expected. It’s a nice tool, noteworthy is integration of NetBeans with subversion, it is trivial to revert to earlier versions in the repository. In addition to repository saves NetBeans graciously keeps track of all ‘local’ saves to the file system. This means that whenever I get a file to a point where I can’t figure out what’s going on anymore, I can easily recover -- a very nice touch, that I make use of all too often.

No comments: