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.setName(“A New Show”) :}.
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

No comments: