DigitalJoel

2010/02/13

Spring Roo and JSF 2?

Filed under: development — Tags: , , , , , , , , — digitaljoel @ 2:07 pm

In my latest project we’ve been playing with Spring Roo.  You can read all about the advantages of it on that site, but the gist is that it creates your entities and JPA persistence code for them.  It will also configure your database connection, generate unit tests, generate a JSP/JSTL based UI with all of the Spring MVC controllers, and selenium tests for it.  It will also optionally integrate Spring Web Flow into the mix.  It’s basically a web based CRUD application in a box.

I spent the last 3 days trying to figure out how to use JSF 2 in Glassfish 3 with a Roo generated application.  Much of this pain may have been caused by my lack of experience with JPA and Spring, but here are a few of the difficulties I faced.

  • JSF 2 is not well supported in eclipse yet, whereas Netbeans 6.8 has excellent JSF 2 support.
  • All of the entities created by Roo just have properties.  All of the getters, setters, and other methods are all included in aspect files and compiled into the entity through AspectJ.  The AspectJ plugin for eclipse takes care of this if you have weaving enabled.  Guess what… There’s no aspect based plugin available for Netbeans, so you get a ton of compile problems in your Roo generated project if you try to open it within Netbeans.
  • The Roo projects are all maven based.  I have yet to see really good success with any maven integration within Eclipse.  Netbeans maven integration is spot on.  For the past 2.5 years I’ve been developing within Eclipse and simply doing all of the maven stuff from the command line because it’s much simpler than dealing with Maven in Eclipse.
  • JSF can’t be used to call Spring MVC controllers.  The Spring MVC controllers generated by Roo are nice.  They are simple and clean, and having them managed by Roo is just that much better.  Unfortunately, Spring MVC is stateless, whereas JSF is stateful, so calling any Spring MVC controller from JSF without using Spring’s Web Flow just doesn’t work.
  • JSF 2 can’t be used in the current version of Spring Web Flow.  Even though a sub component of Web Flow is Spring Faces, the current version of Spring Faces only supports JSF 1.x.  As soon as I put Spring Faces in the classpath, my JSF 2 app wouldn’t render any .xhtml files for me.  Removing Spring Faces from the classpath allowed me to render .xhtml with JSF 2.
  • The transaction type specified in the Roo generated persistence unit is RESOURCE_LOCAL.  Glassfish 3 told me I had to use JTA.  I believe Roo can generate a jndi based data source, which I haven’t tried yet.  I ended up manually modifying the persistence unit (after a lot of time on Google) to be jndi based and have the JTA transaction type.  Unfortunately, this means that all of the Roo generated unit tests fail.  I suspect if I had Roo generate the jndi data source then the unit tests would also pass, so hopefully this issue was self inflicted.  Update: I created a simple project with a jndi datasource.  Unfortunately, all of the unit tests fail.   There is some information in the (closed as won’t fix) bug at https://jira.springsource.org/browse/ROO-311 It would be nice if the unit tests that are created for Roo would use the Spring SimpleNamingContext (and I may be just making stuff up now because I don’t know a lot about Spring/JNDI stuff) or something to allow the unit tests to run if the persistence setup uses jndi.

So why would I continue in my endeavor to use JSF 2 with my Roo project, and where do I go from here?

We are trying to make development as easy as possible for the designers.  They have next to no Java experience at best and just want to tweak styles, layout, and images.  I believe JSF can do a great job of giving us that separation.  I can get the controls working in the form, and they can move them around and do whatever they want with them.  Also, with the composite components in JSF 2, we should be able to make some very nice reusable components for the designers to use in our application.  Finally, many of those components we should be able to share with other projects in the company.

So what is the solution to all of the above problems?

  • Education.  Obviously learning more about JPA and Spring will make the whole journey a little easier for me.
  • Separate projects.  If we have all of the domain model in one maven project, and have the web based UI in another (which is how it really ought to be anyway) then the java developers can use Eclipse or STS for their IDE and get the AspectJ support, and the web designers can use Netbeans 6.8 for the JSF 2 project and get the great support there.  Because the domain model will simply be a jar dependency for the web project all of the aspect based methods will be compiled into the class, meaning we won’t need any Aspect support within Netbeans.

What would it take to get a JSF 2 UI generator into Roo?

  • The Roo team has released a nearly 100 page document about Roo.  Unfortunately, all of the parts about how to implement a new addon for Roo are marked as TBC.  There’s precious little detail on the web too.  Unfortunately, I’m not quite ready to dive into the source code to try to figure it out.  So, a simple Roo addon isn’t quite there.  Update: The only reference I found regarding writing your own Roo addon is at http://www.slideshare.net/desmax74/spring-roo-internals-javaday-iv and the slides leave a lot to the imagination of the reader.
  • Rumors in the Spring forums are that Spring Faces is going to be a new top level project, freed from the grasp of Spring Web Flow, and that the next version (due in June 2010?) will support JSF 2.  I was quite excited to use Web Flow with JSF 2 for the bean management relating to flows.  For instance, a new whatsit wizard that spans multiple pages and manages the scope of the new whatsit bean.
  • Because JSF doesn’t work so well with Spring MVC without Web Flow, and Web Flow won’t support JSF 2 until Spring Faces is split out and both Web Flow and Spring Faces release their next version I believe it’ll be months at best before we see any JSF 2 capabilities within Roo.  The only way it could happen sooner is if someone dives into the Roo source code and creates a third-party addon that will generate JSF 2 controllers and xhtml pages.

So, there it is.  At least 3 days of pain, trial and error, and research all wrapped up in one blog post.

2010/02/09

What’s in a name?

Filed under: development, java — Tags: — digitaljoel @ 11:27 pm

At work I’m in a committee where we are discussing a versioning strategy for one of our legacy projects. I’m not involved directly with the project, but they pulled me into the committee because of my experience with subversion on our current project. In a part of this meeting, we were talking about the database.

In the application I work on, we are able to version the database. So far, it is small enough that we can copy it in a couple of hours, then run the migration scripts on the new database for the new version, and finally point the new application code at the new database. It’s all quite simple really. Then, if things go awry during the release, we can simply replace the webapp with the old version and point back at the old database. In our case, the database name is the application name, followed by the version. For instance, app-1.7.4. When we do the next release, all the data in app-1.7.4 is copied into app-1.7.5. Anyway, you see what I mean.

So I mentioned this in the meeting today. The DBA for the legacy project looked at me as if I was speaking sacrilege. His eyes were wide as he said;
“You actually change the name of the database for every release?!”
My Response: “Well, yeah. That’s the magic of JNDI. My app doesn’t care about the name of the database it’s pointing at, we just set that up in the JNDI properties and merrily go along.”

So, what’s in a name? I’ll admit I don’t have the most experience in technologies other than Java. This isn’t peculiar to Java web applications, is it?

2010/02/02

So Long Kenai

Filed under: development, java, tools — Tags: , , , — digitaljoel @ 11:25 pm

A couple of my recent posts have dealt with JSF 2 and Google’s app engine for Java. I was experimenting with this stuff in a small hobby project that was role-playing game related. It’s been benched for another role-playing game related project that I’m going to be writing in C# in XNA, but before I get to that, I want to say a fond farewell to Kenai.

This morning I had an email from the Kenai team in my inbox. Now that Sun is a part of Oracle, it has been decided by the powers that be on the Oracle side that hosting free, open source projects doesn’t help the bottom line. I think this is really unfortunate. Kenai had a really great integration story with Netbeans.

Kenai included free use of Jira, a wiki, Subversion hosting, downloads, and all of it integrated seamlessly with Netbeans. Setting up my project on Kenai was actually a joy. I simply clicked the menu in Netbeans 6.8 to “share this project on Kenai” and everything just worked. When I then went to my desktop from my laptop, I was able to “get” the project from Kenai and it checked it out, allowed me to login to Kenai and look at my jira tasks and modify them within Netbeans.

I haven’t used any other project hosting solution, but I’ve viewed plenty of projects in google code and sourceforge and have yet to see such a complete story. If I had the money to spare for a pet/hobby project I would certainly go to jira studio, but I suspect I’m going to have to find something a little more free to move my project too. I am happy that I didn’t have too much invested in Kenai, but it’s pretty sad that it’s been killed.

So long Kenai, it was good to know you while it lasted.

Update:
I just got this email from the Kenai folks. Fortunately, it looks like good news, and I think it will be a great benefit to all the projects on java.net.

Gentlepeople,

In an effort to get information out to the Kenai community quickly, while trying to manage the integration of our two companies, I think we did a poor job at communicating our plans for Kenai.com to you. I would like to remedy that now. Our strategy is simple. We don’t believe it makes sense to continue investing in multiple hosted development sites that are basically doing the same thing. Our plan is to shut down kenai.com and focus our efforts on java.net as the hosted development community. We are in the process of migrating java.net to the kenai technology. This means that any project currently hosted on kenai.com will be able to continue as you are on java.net. We are still working out the technical details, but the goal is to make this migration as seamless as possible for the current kenai.com projects. So in the meantime I suggest that you stay put on kenai.com and let us work through the details and get back to you later this month.

Thanks for your feedback and patience.

Ted Farrell
Oracle Corporation

Blog at WordPress.com.