0 Replies Latest reply on Mar 23, 2006 2:01 PM by Peter Goldstein

    JSF, Managed Bean Creation, and JBoss ClassLoaders

    Peter Goldstein Newbie

      I'm having a JSF issue that seems (at least from the stack trace) to have its root cause in a JBoss class loader issue. I was hoping someone on this list might be able to help shed some light on the problem.

      I'm running JBoss 4.0.3SP1, with the EJB3 final draft upgrade (RC5?) and a version of MyFaces that's been upgraded to 1.1.1. I'm using Facelets 1.0.3.

      I have a session scoped bean defined in my managed bean list in faces-config.xml. It's defined using the XML snippet:

      <managed-bean>
      Used for managing localized dates for weeks.
      <managed-bean-name>weekBean</managed-bean-name>
      <managed-bean-class>us.emotive.challengeme.components.program.WeekBean</managed-bean-class>
      <managed-bean-scope>session</managed-bean-scope>
      </managed-bean>

      Now, I should be able to invoke the managed bean creation facility from Java code. This facility should check for a pre-existing bean with that name, and create a new WeekBean if one doesn't already exist in scope.

      I call this facility using a code snippet like:

      FacesContext facesContext = FacesContext.getCurrentInstance();
      ValueBinding vb = facesContext.getApplication().createValueBinding("#{weekBean}");
      WeekBean weekBean =
      (WeekBean)vb.getValue(facesContext);

      I would expect this to yield a WeekBean. Instead I get an exception and a long stack trace. In the trace I see this:

      Caused by: java.lang.ClassNotFoundException: No ClassLoaders found for: us.emotive.challengeme.components.program.WeekBean
      at org.jboss.mx.loading.LoadMgr3.beginLoadTask(LoadMgr3.java:198)
      at org.jboss.mx.loading.RepositoryClassLoader.loadClassImpl(RepositoryClassLoader.java:475)
      at org.jboss.mx.loading.RepositoryClassLoader.loadClass(RepositoryClassLoader.java:377)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:251)

      This is odd because:

      i) If I use a reference to weekBean in a JSF/Facelets page, as opposed to a backing bean, everything gets instantiated fine.
      ii) I can alter the above code to look like:

      FacesContext facesContext = FacesContext.getCurrentInstance();
      ValueBinding vb = facesContext.getApplication().createValueBinding("#{sessionScope.weekBean}");
      WeekBean weekBean =
      (WeekBean)vb.getValue(facesContext);
      if (weekBean == null) {
      weekBean = new WeekBean();
      vb.setValue(facesContext, weekBean);
      }

      and all the classes get loaded and instantiated just fine.

      I'm suspecting a bug, but considering the number of different technologies involved I'm not sure where. I was hoping someone on this list might have a clue, and help me cut short the process of swapping in and out different components.

      Has anyone seen this before? Is this a known issue? Anyone know whether this is a bug or I'm doing something wrong? Any guidance would be appreciated.