0

Using the requestContext demo example in my system http://www.primefaces.org/showcase-labs/ui/requestContext.jsf

I am getting the following error

Caused by: java.lang.ClassCastException: org.primefaces.context.DefaultRequestContext cannot be cast to org.primefaces.context.RequestContext
at org.primefaces.context.RequestContext.getCurrentInstance(RequestContext.java:38) [primefaces-3.4.1.jar:]

the error occur when the java command running

RequestContext context = RequestContext.getCurrentInstance();

Using primefaces-3.4.1 under jboss seam 2.3.0.Final with Jboss AS 7.1

Amir

shasho
  • 131
  • 2
  • 13

1 Answers1

1

You've multiple different versioned PrimeFaces JAR files in your webapp's runtime classpath. For example, one PrimeFaces 3.3 and another PrimeFaces 3.4.1. They're conflicting with each other.

Cleanup the webapp's runtime classpath so that only the most recent version remains and this problem should disappear. Paths which are by default covered by the webapp's runtime classpath are the webapp's own /WEB-INF/lib folder, server's and/or JRE's own /lib and /lib/ext folders.


Update: another, actually more rare, cause is that you've multiple PrimeFaces JAR files of the same version which are loaded by different classloaders. The getClass() on the both classes would then never match the == check. You'd need to remove one of both.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • In my Jboss AS 7.1 I have two primefaces-3.4.1.jars. one in "WEB-INF\lib" and the other in "ear\lib". The are identical. Thus this is NOT the problem – shasho Oct 24 '12 at 14:42
  • They're loaded by different classloaders and hence not the same. Remove the one or the other. I'd say, the one in `/ear/lib` is at the wrong place. What has a front end library to do in the back end? Are you sure that the back end code is free of front end dependencies? You might otherwise need to rewrite some back end code so that it's free of all incorrect `javax.faces.*` and `org.primefaces.*` imports. – BalusC Oct 24 '12 at 14:53
  • Which error exactly? The same? Then you've apparently another one elsewhere in the webapp's runtime classpath. – BalusC Oct 24 '12 at 15:31
  • when removing the jar from ear/lib I get the error "Caused by: java.lang.NoClassDefFoundError: org/primefaces/context/RequestContext" when removing from \WEB-INF\lib it worked thanks !!! meaning that when adding the jar to the ear/lib one need to delete it from the \WEB-INF\lib even they are in the same version ! – shasho Oct 24 '12 at 16:00
  • That's just strange. This suggests that your JSF code is still not there where it belongs in spite of my previous comment (it belongs exclusively in the WAR and thus **not** in the EAR/EJB), but ala, that's a different problem :) – BalusC Oct 24 '12 at 16:02