Thursday, January 24, 2008

RoR => Seam Part 1

This is a short initial post about my first jboss seam project which is to move one of my small, but non-trivial Ruby-on-Rails applications to Seam.

A couple of preliminary notes:

I used seam-gen to generate the initial code/application structure. It gives you a good start -- the pages have a nice minimal and professional look to them and none of the default designs/layouts flows are crazy. All in all a nice job.

My environment Mac OSX 10.5.1, jboss 4.2.2 GA, seam 2.0.0 GA, mysql 5.0.45
I had a couple missteps/odd experiences that I wanted to share. They both revolved around trying to include some AJAX capabilities on a page

One page of the application is for the creation of shows which have titles, curators, institutions and artworks. The curators, institutions and artworks are in separate tables with the ‘shows’ table holding foreign keys. Title is a required field.

In AJAXifying the curator selection the onkeyup actionListener was not being called -- I was getting this error message in the background stream
14:07:00,243 INFO [lifecycle] WARNING: FacesMessage(s) have been enqueued, but may not have been displayed.sourceId=shows:aName Decoration:name[severity=(ERROR 2), summary=(value is required), detail=(value is required)]
The referenced aName section of the page was not involved in either end of the AJAX update. After struggling with this for a few days I realized that Name is a required field -- the framework was checking this requirement first and giving me an error. The combination of the error in validation + being in the middle of an ajax call resulted in neither the error being posted to the page nor the onkeyup action being called.

I worked around this by initializing the name on the page with a
#{empty showsHome.instance.name ? showsHome.instance.setName(“A New Show”) : showsHome.instance.name}.
I find the behavior odd and of course the workaround doesn’t cover the situation in which the user clears the title field and then jumps to the curator field.

Staying with the topic of AJAX support: keep in mind that the richfaces toolkit provides a lot of ajax functionality in a straightforward manner. For example, when looking for an ‘autocomplete’ functionality I mistakenly went down the path of trying to integrate a Yahoo UI component -- nothing against the YUI toolkit, but the exact functionality I was looking for was in richfaces & required a lot less work.

Using richfaces with seam isn’t as obvious as it should be since most of the examples that you’ll currently find are for Seam version 1.x prior to the richfaces mindmeld that occurred in Seam 2.0. Caveat: be sure to use richfaces 3.1.3+ since I found some of the most important rich:suggestionbox features broken in earlier versions

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.