Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

ManagedBeanCreation, JSF, and ClassLoading

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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>
<description>Used for managing localized dates for weeks.</description>
<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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic