Wednesday, May 23, 2012

JSF 2 integrated with Struts 2 research

I have been trying to move application development out of the JSP ages for some time.  JSP is well known and numerous developers are capable of supporting it but in many cases the results are underwhelming.  Given more time, fewer projects and more senior developers maybe we could do a better job of making sure consistent JSP designs/implementations are always used.  The primary goals being improving quality, reducing errors and easing maintenance/enhancements.  The project work-load is only expected to increase over the next two years due to various grants and large projects already in planning/progress. The solution I decided on is the use of a component model (JSF 2) and related component suites.  This reduces the need for lots of custom JavaScript (and expert JavaScript knowledge) and gains a lot of cross-browser testing by communities supporting many of the JSF libraries.  The existing and upcoming applications/tools/utilities are using Struts 2 and JSP as the base technology but a "Struts 2 JSF plugin" allows integration into the Struts 2 environment.  There are some posts/comments indicating that Struts 2 with JSF might have some benefits over a purely JSF implementation (authors preferring the Struts 2 navigation from what I can tell).

I previously toyed with JSF 1 for some time and was put off a bit by it and poor tool support in older versions of Eclipse.  I had been toying with IceFaces 1.8 while trying to work with Mojarra or Apache MyFaces.  I like aspects of IceFaces but fear getting sucked into needing paid support or the commercial components.  There were also problems just getting it all working.  So I let this research stagnate for a long time.

Upcoming projects inspired me to look into JSF again.  I am pleased with the JSF 2 support in Eclipse (3.7.2) now.  I made a somewhat informed decision to switch over to PrimeFaces 3.2 from IceFaces.  I also switched over to Mojarra.  I am a fan of Glassfish (but use Tomcat more) so having this consistency (by using Mojarra) makes sense for now.  I had performed some research into RichFaces, IceFaces 2/3, Apache Trinidad and some others before settling on PrimeFaces.  It appears to have a good selection of components, reasonable performance and a helpful community.  There isn't anything fundamentally wrong with the others but this seemed like a better fit and initial prototyping was successful earlier than with other options. 

Even though integrating new functionality using JSF into a moderate sized Struts 2/JSP application isn't trivial, it is going reasonably well.  I hope to also replace some limited functionality with JSF over the next few weeks.  This will provide an opportunity to target internal-only users with the result of the much more refined functionality and help justify future updates which are public facing.

My only major disappointment is a lack of comprehensive examples which show small scale but somewhat realistic implementations specifically for JSF 2.  There is lots of JSF 1 information which doesn't reflect current best practice for JSF 2.  I expect to be working in the debugger and reviewing generated HTML for a while until I figure out good ways to promote efficient results.

As a side note, I also took a stab at integrating JBoss Seam but that wasn't going as well as hoped.  Again, there are some good things there but I prefer something which is an improvement and easy to get functional quickly.  I was spending way too much time trying to figure out Seam issues rather than generating useful work results.  If we ever have to convert to JBoss then this would likely be an easier move but in the foreseeable future Tomcat 7 is the best fit with JSF 2/Struts 2/PrimeFaces 3 with some Glassfish 3 thrown in here and there.  I dumped WebLogic - Swiss army knife which is bloated, expensive and hard to integrate into our overall infrastructure. 

4 comments:

  1. As an update, as a prototype, I was able to add new functionality and replace some existing functionality with a JSF 2 implementation. It was not too hard adding JSF pages/components but I ran into some problems trying to refer to Struts actions from JSF 2 (PrimeFaces 3). I was able to work around the issue but the result isn't quite what I was hoping for. Possibly just me or maybe a bug in the Struts JSF plugin. There is so little documentation on using the Struts JSF plugin - I am not considering it a long term solution but it does help with the current needs. The only other substantial hurdle is security - likely need an interim solution until I can implement either Spring security, JASIG CAS and/or Apache Shiro. There may be a couple other options but I'll have to go back and review them again.

    ReplyDelete
  2. Hey thanks a lot for your post, it was very helpful for me.
    Based on your latest comment, it looks like the JSF/PrimeFaces+struts2 path is a little too rocky for a long term solution. Is it still your opinion?

    ReplyDelete
    Replies
    1. Yes, at this point in time it seems like a difficult long term solution. I will hopefully be able to evaluate things again once JSF 2.2, PrimeFaces 3.5/4.0 and hopefully an updated Struts release are available. Maybe the combination of more time to familiarize myself with things along with a few bug fixes will make the difference.

      As it stands now, I will likely have to make this solution work for the foreseeable future for lack of time to do a pure JSF/PrimeFaces conversion.

      Delete
  3. Hi thanks for this post. I´m trying to integrate "Struts2-jsf-plugin" with an appFuse project and i´m having problems to works it. I would like to integrate Primefaces components but using struts2 as controller, is it possible?.

    I have read you had many problems to refer to Struts actions from JSF 2 (PrimeFaces 3). I would be grateful if you could indicate me where i can find a simple example. I havent found any example with struts2 and Primefaces. Thanks

    ReplyDelete