java.lang.NoClassDefFoundError: javax/faces/context/FacesContext error

Hi ,

In web.xml , i have the following mapping :

--

<!-- Faces Servlet Mapping -->

<servlet-mapping>

<servlet-name>Faces Servlet</servlet-name>

<url-pattern>*.jsf</url-pattern>

</servlet-mapping>

--

In the managed bean , I have following method

--

public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {

if ((context == null) || (component == null)) {

throw new NullPointerException();

}

if (value != null) {

String val = (String) value;

if (val == null || val.trim().length() == 0) {

throw new ValidatorException(MessageFactory.getMessage(context, "Name should not be empty" ,

new Object[] {val} ));

}

}

}

--

This method is for validation and it uses FacesConteact and it fails here. I have all the needed jars. The application works fine as long as FacesContext is not used in managed bean code

I

Any ideas ?

[1070 byte] By [dhirendra123a] at [2007-10-2 8:40:09]
# 1

I'll take a shot in the dark here... It doesn't sound like what you are describing but sometimes something seemingly unrelated is the root of the problem.

Perhaps it is not finding the MessageFactory? In my JSF implementation the MessageFactory object is declared as private and it won't let me use it. I had to rewrite my own.

CowKing

IamCowKinga at 2007-7-16 22:42:00 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
I am using Sun reference implementation. I added my own MessageFactory class, but still the same error.I am following guessnumber example from Sun reference implementation.Thanks
dhirendra123a at 2007-7-16 22:42:00 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

Hmm... Ok. Do all your web pages end in .jsf? Since you've set in your web.xml that everything with the URL pattern of *.jsf will pass through the faces servlet, you need your file to have a jsf extension.

i.e. http://localhost/contextRoot/myPage.jsf

And of course, in your web.xml, you have the following lines right?

<servlet>

<servlet-name>Faces Servlet</servlet-name>

<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>

<load-on-startup>-1</load-on-startup>

</servlet>

CowKing

IamCowKinga at 2007-7-16 22:42:00 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

Hi ,

I have the following in web.xml :

<servlet>

<servlet-name>Faces Servlet</servlet-name>

<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>

<load-on-startup> 1 </load-on-startup>

</servlet>

It is PLUS ONE instead of MINUS ONE for <load-on-startup>

dhirendra123a at 2007-7-16 22:42:00 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
Webpages are saved as .jsp pages.But in the URL , i invoke them with .jsf extemsion and they seem to automatically get translated and appropriate page with same name and .jsp extension gets invoked.
dhirendra123a at 2007-7-16 22:42:00 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

Yes, that all sounds right. Hmm...

Probably a silly question, but have you ensured that the jsf-api and jsf-impl JARs are in the WEB-INF/lib directory?

This has me a bit stumped, I'm sorry to say. It's probably something small that is easily overlooked. Try watching your punctuation. Maybe try mapping the Faces Servlet to /faces/* and see if that makes a difference (of course, you'll have to adjust your URL appropriately).

Out of curiousity, where exactly does this fail? Have you been able to narrow it down to the exact call?

CowKing

IamCowKinga at 2007-7-16 22:42:00 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7

I got it to work.

Managed Bean class was in two places - one inside the WAR file and second one outside of the war along with some other classes in the EAR file.

managed bean from other classes in the EAR file was getting picked which did not have any idea of the FacesServlet or any other Faces classes.

I excluded the managed bean from second place in the build script and eevrything seems to be working fine.

Thanks for your help !!

dhirendra123a at 2007-7-16 22:42:00 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...