Wednesday, August 14, 2013

JSF 2.2 with Google App Engine: A Hurricane of Errors

Three days trying to do what should be a simple upgrade from the JSP Hello World to JSF and it still isn't working.

Long story short, when you get started with Google App Engine you'll find a nifty tutorial from Google that gets you up and going with a simple Guestbook JSP project.  I use Maven with my Eclipse so I used the Maven Archetype instead (also JSP).  At the time I was unable to find a detailed tutorial that starts with JSF to begin with.  There will be a future post with my experience of using that one instead (UPDATE: done, see this post).

As is, I setup the configuration for JSF and Apache MyFaces doing it the old-fashioned, manual way.  I had problems finding documentation on how to do it (and couldn't even find it again).  So, this is what NOT to do:

  1. Include Apache MyFaces in your Maven dependencies.
  2. Update your web.xml to be at least version 2.5 (this is actually a good idea) and include the following
(UPDATE: below code is properly presented now)

  Faces Servlet

  Faces Servlet
  3. Put a simple JSF hello world file into your /faces directory and load it up.  Even better, don't use an EL #{} expression so that you don't know that EL is broken until much, much later.

As stated, this worked three years ago with Eclipse 3.6 or so, but NOW Eclipse 4.3 Kepler has a concept called Project Facets under the Project properties screen and if you don't specify that you're using JSF here... it blows away your custom web.xml to the default jsp version.  This was Gotcha #1.

After reverting that mess and configuring the Facet I'm expecting a smooth ride... but get the now dredded: javax.naming.InitialContext is a restricted class error, and try the fix suggested by the link just previous.  I do not catch the subtext that this fix is only for Sun's (not Apache's) JSF implementation, and for an older version than I'm using at that!  So I change to Sun's JSF, track down the new and comment out the needed code and at least it compiles but it still doesn't work, so I go back to MyFaces, download the source and comment out their references that I track down.  Then I have to track down a couple of other libraries that the one source file uses and it finally compiles.  At least the Hello World works at this point.  Now I know that the more recent JSF implementations have this issue fixed!  So don't mess around with commenting out the InitialContext code, just change the JSF implementation (the latest Mojarra works).  If you're keeping track, these are Gotchas 2 to 7.

Upgrading to Facelets is as easy as it is supposed to be.  However, this is when I realize that my EL isn't working.  After trying and reading various articles I came across new errors.  I found that I got ClassNotFoundException: javax.faces.webapp.FacesServlet and the ELResolvers for JSF were not registered with the JSP container not because it could not be found, but because it could be found too often (and I had to include it as provided instead of as a jar).  The novel cannot_find_facelet_taglib turned out to just be an Eclipse thing.  All in all, I still wasn't able to patch it up after finding about 6-12 other gotchas.

No comments:

Post a Comment