Netbeans 12 - JSF 2.3 Logs

javax/enterprise/context/spi/Contextual

Log Excerpt

java.lang.NoClassDefFoundError: javax/enterprise/context/spi/Contextual
at com.sun.faces.application.view.ViewScopeManager.(Unknown Source) at com.sun.faces.application.view.ViewScopeManager.getInstance(Unknown Source) at com.sun.faces.application.view.ViewScopeEventListener.processEvent(Unknown Source) at javax.faces.event.SystemEvent.processListener(Unknown Source) at javax.faces.event.ComponentSystemEvent.processListener(Unknown Source) at com.sun.faces.application.ApplicationImpl.processListeners(Unknown Source) at com.sun.faces.application.ApplicationImpl.invokeListenersFor(Unknown Source) at com.sun.faces.application.ApplicationImpl.publishEvent(Unknown Source) at javax.faces.component.UIViewRoot.getViewMap(Unknown Source) at javax.faces.component.UIViewRoot.getViewMap(Unknown Source) at com.sun.faces.mgbean.BeanManager$ScopeManager$ViewScopeHandler.handle(Unknown Source) at com.sun.faces.mgbean.BeanManager$ScopeManager.pushToScope(Unknown Source)...

Background

How did we get here? Well, we were trying to create a JSF 2.3 dataTable in Netbeans 12, to run in the browser using Apache Tomcat 8.5. Other JSF files, mainly a LoginBean class and login.xhtml file ran fine. But when we launched a page (home.xhtml) with a dataTable design, right away we were met the log errors. Then, we decided to dig around for clues and found that, in JSF 2.3, Contexts and Dependency Injection (CDI) beans do not run without the proper JSF configuration, thus additional tasks were needed in our Netbeans 12 environment. The logs collected were straight forward but we had yet to dive into Netbeans programming, we knew it would take a little bit of looking through to figure it out. Our advice is, is to plug part of error logs into a search engine to fetch results. We did in fact search multiple sites to find the right clues and get on with it; related data on the site(s) and our approach to fixing the issues in Netbeans will be added a bit later.

How do we fix this?

Well! provided that you have a similar environment, Netbeans 12.x, and running Apache Tomcat 8.5, with the JSF 2.3 Framework, you are half way there... As we have learned, a bean.xml file is needed in your configuration. Here are the contents of that file:



Our web.xml file also needed to be configured in a manner that would support the Apache Tomcat environment. Here is what it should look like:

Activate CDI Beans

You will then need to activate the configuration for Java Server Faces (JSF) beans. In this case, just writing the code to enable JSF 2.3 technology in your environment will not do. You may find that you need to download and include specific CDI JAR files for your imports, shown in the following:

Download CDI JAR files

We downloaded the following JAR files and imported them into the Libraries section within Netbeans project. Please be aware this is project-specific:

Include face-config file (optional)

In some cases, a Face-Config.xml file is required but within Netbeans 12, this was not necesary. However, you should have this information, in case you are configuring a different IDE:

Kudos, Credits

In closing, none of this would be possible without first searching online- Some posts came up pretty close but kudos and credits go to this Hantsy Blog: http://hantsy.blogspot.com/2017/11/activating-cdi-in-jsf-23.html. We were able to complete our configuration without issue after trying some of the steps on that post.