Sunday, January 1, 2012

JSF 2.0 Managed Bean Annotations and CDI on WebLogic 12c

WebLogic 12c now supports Java 6 so we can now try out the JSF 2.0 Managed Bean annotations together with CDI JSR-299. In this blogpost I will use OEPE 12c as my IDE and deploy everything on WebLogic 12c. Off course I will tell you my experiences to get all this working in Eclipse and WebLogic 12c.

First let's start with the JSF 2.0 Managed Bean Annotations.

We need to remove the managed bean definitions from the faces-config.xml file. Then make sure that you don't use the metadata-complete attribute ( metadata-complete="true" ) on the faces-config element, this will disable the search for JSF Managed Beans.

Then we can add the JSF Managed Bean annotations to the java class. We can use @ManagedBean ( javax.faces.bean ) together with the right scope annotation like RequestScoped, SessionScoped or ViewScoped ( CDI does not have this View Scope ). You will see this bean in the Faces Configuration View.

Next part of this blog is about CDI, this will be more tricky, it is possible but does not work so well in OEPE and WebLogic. I didn't have these problems with the same OEPE, Code and using Glassfish 3.11.

So to enable CDI we need to add a beans.xml file to the WEB-INF folder. Like this with a empty beans element, this will trigger CDI.

When we try to run the JSF application again then you probably will hit this NPE in the jboss Weld framework.

<javax.enterprise.resource.webcontainer.jsf.renderkit> <BEA-000000> <javax.faces.FacesException
at com.sun.faces.context.ExceptionHandlerImpl.handle(
at com.sun.faces.lifecycle.Phase.doPhase(
at com.sun.faces.lifecycle.LifecycleImpl.render(
at org.apache.myfaces.extensions.validator.core.startup.ExtValLifecycleWrapper.render(
at javax.faces.webapp.FacesServlet.service(
Truncated. see log file for complete stacktrace
Caused By: java.lang.NullPointerException
at org.jboss.weld.el.ELCreationalContextStack.getCreationalContextStore(
at org.jboss.weld.el.WeldValueExpression.getValue(

The solution is to remove the JSP entries and rename your files from jspx to xhtml.
From this.

<?xml version="1.0" encoding="iso-8859-1"?>
<jsp:root xmlns:jsp="" version="2.0"
  < contentType="text/html;charset=utf-8"/>
    <tr:document title="Bean and ExtVal validation">

To this, where we define the used jsf namespaces on the html element. 

Next we can try to create a new managed bean where we will use the Named annotation together with the SessionScoped annotation of javax.enterprise.context

We can also inject an EJB or a Managed Bean with the Inject annotation.

I can also replace @EJB with @Inject but then I should move my EJBs to my Dynamic Web Project else I will get an Weld error.  Probably with OEPE you have an different JPA project and this ejb.jar will be deployed together with the WAR in an EAR. 
I didn't test this but you need to enable CDI on this ejb project or EAR.

That's not all you also need to change the WebLogic Publishing mode of OEPE. This should be Publish as an exploded archive else Inject won't work. ( Thanks to Steve Button for the tip. ).

This is the error I got WELD-001408 Unsatisfied dependencies for type [DataBeanCDI] with qualifiers [@Default] at injection point [[field] @Inject private nl.amis.web.beans.DataBean.dataBeanCDI]

This is solved in the WebLogic 12c (12.1.1) patch release of March 2012, so no need for an exploded archive

And now the most annoying bug, the CDI managed beans will work only once on WebLogic 12c. When you deploy or run your application the second time then the CDI Managed bean can't be found. The solution is you need to restart the WebLogic Server. This makes development with CDI almost impossible.

This is also solved in the WebLogic 12c (12.1.1) patch release of March 2012

I also added and removed a patch which makes everything even a little better

So, I removed with the BSU utility the following patch

and  installed

13893259 SU Patch [QPXR]: MERGE LABEL REQUEST ON TOP OF FOR BUGS 13482794 13563205 13572075 13572176

Also enabling fastswap in the weblogic-application.xml ( ear project ) can help you in solving weld errors.

Here you can find my example code.


  1. this is good and helpful
    i ran into a bug-type situation in weblogic 12c

    maven project where jsf dependency was not declared as provided (so the jar would end up in web inf lib)

    netbeans 8 and weblogic 12c

    the symptom was this, Managedbean annotation would work and Named would not

    I spent an entire day debugging before i found out!

    I was looking for some magic way to enable CDI


  2. Current OEPE does not support JSF 2, and features like auto-complete for @ManagedBeans do not work, I have to add declaration in faces-config.xml. Did you get around it? It's really frustrating that support for JSF 2 is not available.