Searching for “JBoss 5 with JSF 2” results in a bunch of messages explaining that “it can’t be done,” or “it shouldn’t be done,” or some other nonsense like “just remove JSF from JBoss” which obviously will break any already existing web application and is not an option in a production environment. The following is the solution and allows a web app in JBoss 5.0.1GA to use JSF 2 while leaving the built in JSF 1.2 on JBoss alone. So I think this is what people are actually looking for when they search for “JSF 2 with JBoss 5.” Note: I haven’t tried getting this to work with “MyEclipse,” only plain old Eclipse.
- Add the following three things to web.xml
<!-- JSF 2: this tells JBoss 5 to use the jsf jars included in the app -->
<!-- JSF 2: this needs to be included to avoid an error message -->
<!-- JSF 2: use pages named .xhtml instead of .jsp. -->
- Download the latest version of JBoss 6 (which I’ve heard you should upgrade to as soon as practical).
- Copy the following jars from JBoss 6 into the WEB-INFlib directory.
- Rejoice in JSF 2 goodness.
If you read the stuff you were copying and pasting then you’ll notice that .xhtml is used instead of the default .jsp. The additional information above should be everything necessary to get a basic example to work – the one at http://www.coreservlets.com/JSF-Tutorial/jsf2/#Getting-Started is the one I used.
Common Error Messages
You may run into these when trying to use JSF 2 on JBoss 5 without doing what’s listed above.
- java.lang.ClassCastException: com.sun.faces.config.WebConfiguration cannot be cast to com.sun.faces.config.WebConfiguration
- Make sure all entries exist in the web.xml. This means JBoss found both versions of JSF and doesn’t know which one to use. JBoss 5 has JSF 1.2 as part of it’s normal libs, so including JSF 2 with an app will cause problems unless we tell JBoss to only use the jars from our app.
- java.lang.NoClassDefFoundError: org/jboss/mc/servlet/vdf/spi/VDFConnector
- Make sure all of the specified jar files were copied and are included. JBoss is saying “what is this class VDFConnector? Never heard of it..
- java.lang.NoClassDefFoundError: (anything)
- Make sure all of the specified jar files were copied and are included.
- JSF1029: The specified InjectionProvider implementation ‘org.jboss.web.jsf.integration.injection.JBossInjectionProvider’ does not implement the InjectionProvider interface.
- Make sure all entries exist in the web.xml. I have no idea why we need to specify the exact thing it can’t find in order to make it work. Any clarification is encouraged.
- java.lang.IllegalStateException: Application was not properly initialized at startup, could not find Factory:
- Try adding
to the web.xml. This was contributed by Kley in the comments. Let me know if it works..
- Try adding
The WAR_BUNDLES_JSF_IMPL option is from Shivaji Byrapaneni at http://community.jboss.org/message/54085.
I can’t find the URL where I found the JBossInjectionProvider option.
The fact that the jboss-mc-int-servlet.jar is necessary is from http://community.jboss.org/thread/2656.
The rest is from me.