Use Ajax4jsf with Seam + Facelets
Ajax4jsf is a very nice open source framework for adding Ajax features into existing JSF components. I have been playing with it in my Seam + Facelets applications. It is great fun. However, as most other Ajax JSF components, Ajax4jsf requires some tweaking to get around the JBoss ClassLoader when working with Seam. The official docs recommend that you put all Ajax4jsf and Facelets library jars into $JBOSS_HOME/server/default/lib as shared libraries. However, the problem is that those frameworks are not designed to be shared. If you have multiple web applications deployed on the same server, the shared lib approach might causes some problems. In this post, I present an alternative approach to use Ajax4jsf inside Seam.
The short answer:
- Bundle the ajax4jsf-seam-war.jar and jsf-facelets-seam-war.jar (if using Facelets) in your WAR file’s WEB-INF directory.
- Bundle the regular required JAR files of Ajax4JSF and Faclets in the EJB3 JAR file in your EAR file.
- Follow instructions in Ajax4JSF docs to setup web.xml and faces-config.xml to use Ajax4JSF with Facelets.
The explanation:
The problem with AJAX JSF frameworks and Seam is that the framework libraries need to be “seen” from both the WAR and EJB3 JAR files. (Non-Ajax frameworks do not have this requirement since they do not need to access the EJB3 “backing beans”.) But libraries in the WAR file is invisible outside of the WAR. So, the solution is to place the libraries in the EJB3 JAR file, which on the classpth of all components in the EAR. But it is not that simple: JSF only searches the WAR for tag definitions and configuration files. So, all the .tld, .taglib.xml, and faces-config.xml files in the library JAR’s META-INF directory needs to re-pakcaged into a seperate JAR and be placed into the WAR file. That’s where the *-seam-war.jar files come from.
But then, why do we need to re-package jsf-facelets.jar as well? The reason is that Ajax4JSF needs to load Facelets by itself. So, it needs to “see” jsf-facelets.jar from outside of the WAR as well.
October 5th, 2006 at 6:02 am
What do you mean by “Bundle the regular required JAR files of Ajax4JSF and Faclets in the EJB3 JAR file in your EAR file”?
I couldn’t find any EJB3 JAR in my EAR. Could you explain that step in detail?
Thanks
October 5th, 2006 at 11:12 am
Sure.
In your app.ear file, you probably have app.war for the web components and app.jar for the EJBs (or business POJOs). The app.jar is what we call “EJB3 JAR” since it contains EJB3 components. Sorry, I should have made it more clear.
June 19th, 2007 at 5:56 am
Hello Michael,
I have similar issues with richfaces. Somehow I can’t get it to run. If I bundle the richfaces jar in my app.jar jboss won’t launch my application. I want to use the richfaces tree component, so I need to implement the treenode interface. I was looking for a richfaces api to bundle that in my app.jar but I don’t think there is one yet. Maybe you can help me out?
November 26th, 2007 at 2:47 am
Something is very wrong using JBOSS 4.2 + Seam 1.2+ ajax4jsf 1.1.1 + richfaces 3.1.0 besause I could not start deployment.
Error:
javax.faces.FacesException: org.ajax4jsf.renderkit.ChameleonRenderKitFactory
I’m using RH Developer studio wizard to do Seam web project with richfaces capabilities, all the components are from JBOSS and it doesn’t work.