Cannot find FacesContext

Hello everyone

I am rather new to jsf and I have run into a big black hole ;-)

After I have deployed my app. and I call my bankUI.jsp through my jsf mapping I get the following error:

javax.servlet.jsp.JspException: Cannot find FacesContext

javax.faces.webapp.UIComponentTag.doStartTag(UIComponentTag.java:405)

org.apache.myfaces.taglib.core.ViewTag.doStartTag(ViewTag.java:71)

... rest of stacktrace ....

This is my setup:

App.server: jboss-4.0.4RC1

web.xml:

<!-- Faces Servlet -->

<servlet>

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

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

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

</servlet>

<!-- Faces Servlet Mapping -->

<servlet-mapping>

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

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

</servlet-mapping>

web-client.war (struture)

bankUI.jsp

meta-inf

...manifest.mf

web-inf

...faces-config.xml

...web.xml

...classes

......sourcefiles...

...lib

......commons-beanutils.jar

......commons-collections.jar

......commons-digester.jar

......commons-logging.jar

......jsf-api.jar

......jsf-impl.jar

......jstl.jar

......standard.jar

bankUI.jsp:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>

<title>

jboss_tutorial

</title>

<head> </head>

<body>

<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>

<f:view>

<h:form id="form">

<h utputText id="overskrift" value="Ralph磗 Bank" style="font-family:Arial, sans-serif; font-size=24;color=green"/>

<h utputLabel for="cprsoeg">

<h utputText id="cprsoegtext" value="Soeg cprnr."/>

</h utputLabel>

<h:inputText id="cprsoeg" value="#{bankUIBean.cprnr}" required="true">

<f:validateLongRange minimum="10" maximum="10"/>

</h:inputText>

<h:message id="errors" for="cprsoeg" style="color:red" />

</h:form>

</f:view>

</body>

</html>

There are no errors on deployment, and my app. runs find. But when i try to acces my bankUI.jsp i get the error above.

And I do go through the correct jsf mapping http://localhost:8080/project_1app/bankUI.jsf

Now if I remove all my jsf related tags from my jsp file (bankUI.jsp) the page is displayed correct. So the error occurs when i hit the first jsf tag on my jsp page.

I also run ejb3.0 on my jboss app server. I don't know if that is usefull information.

PLEASE HELP

Ralph Michelsen

[3004 byte] By [ralphmichelsena] at [2007-10-2 17:49:29]
# 1

Your web.xml appears to be missing the necessary listener entry. Try adding:

<listener> <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>

</listener>

in the appropriate place and see if that resolves your issue.

--Peter

PeterMGoldsteina at 2007-7-13 19:07:37 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

hello PeterMGoldstein

Thank you for your reply. Unfortunatly it did not work. I added the lines you specified as follows:

<!DOCTYPE web-app PUBLIC

'-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN'

'http://java.sun.com/j2ee/dtds/web-app_2.2.dtd'>

<web-app>

<servlet>

<servlet-name>CalculatorServlet</servlet-name>

<servlet-class>org.jboss.tutorial.gui.servlets.CalculatorServlet</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>CalculatorServlet</servlet-name>

<url-pattern>/calculator</url-pattern>

</servlet-mapping>

<!-- Faces Servlet -->

<servlet>

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

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

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

</servlet>

<!-- Faces Servlet Mapping -->

<servlet-mapping>

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

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

</servlet-mapping>

<listener>

<listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>

</listener>

</web-app>

I get the same errormessage as before.

The deployment of my app looks like this in the serverconsole:

08:37:19,781 INFO [JmxKernelAbstraction] installing MBean: jboss.j2ee:service=EJB3,ear=bean.ear,ja

r=calculator_ejb.jar,name=IndlaanSBean with dependencies:

08:37:19,781 INFO [JmxKernelAbstraction]persistence.units:ear=bean.ear.ear,jar=calculator_e

jb.jar.jar,unitName=manager1

08:37:20,562 INFO [JmxKernelAbstraction] installing MBean: jboss.j2ee:service=EJB3,ear=bean.ear,ja

r=calculator_ejb.jar,name=PersonerSBean with dependencies:

08:37:20,562 INFO [JmxKernelAbstraction]persistence.units:ear=bean.ear.ear,jar=calculator_e

jb.jar.jar,unitName=manager1

08:37:20,609 INFO [EJB3Deployer] Deployed: file:/C:/Programmer/jboss-4.0.4RC1/server/default/tmp/d

eploy/tmp24276bean.ear-contents/calculator_ejb.jar

08:37:20,625 INFO [TomcatDeployer] deploy, ctxPath=/project_1app, warUrl=.../tmp/deploy/tmp24276be

an.ear-contents/web-client-exp.war/

08:37:22,703 INFO [FacesConfigurator] Reading standard config org/apache/myfaces/resource/standard

-faces-config.xml

08:37:22,859 INFO [FacesConfigurator] Reading config /WEB-INF/faces-config.xml

08:37:22,968 ERROR [LocaleUtils] Locale name null or empty, ignoring

08:37:27,281 INFO [StartupServletContextListener] ServletContext 'C:\Programmer\jboss-4.0.4RC1\ser

ver\default\.\tmp\deploy\tmp24276bean.ear-contents\web-client-exp.war\' initialized.

08:37:27,296 INFO [EARDeployer] Started J2EE application: file:/C:/Programmer/jboss-4.0.4RC1/serve

r/default/deploy/bean.ear

08:37:27,328 INFO [Http11BaseProtocol] Starting Coyote HTTP/1.1 on http-0.0.0.0-8080

08:37:27,406 INFO [ChannelSocket] JK: ajp13 listening on /0.0.0.0:8009

08:37:27,406 INFO [JkMain] Jk running ID=0 time=0/31 config=null

08:37:27,421 INFO [Server] JBoss (MX MicroKernel) [4.0.4RC1 (build: CVSTag=JBoss_4_0_4_RC1 date=20

0602071519)] Started in 31s:593ms

There is an error on deploy, that i don磘 understand. Maybe you have seen this before?

Regards

Ralph Michelsen

ralphmichelsena at 2007-7-13 19:07:37 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

The locale error is easy - it means that you're missing a locale-config like this one in your faces-config.xml:

<locale-config>

<default-locale>en_US</default-locale>

<supported-locale>en_US</supported-locale>

<supported-locale>en</supported-locale>

<supported-locale>es_ES</supported-locale>

<supported-locale>es_US</supported-locale>

<supported-locale>es</supported-locale>

</locale-config>

Check the faces-config.xml schema for details.

As for your other problems, make sure you don't have multiple versions of the JSF libs in your app. If you're running on JBoss, you'll likely have all the JBoss libs in $JBOSS_HOME/server/default/deploy/jbossweb-tomcat55.sar/jsf-libs

If you package another set of JSF libs in your WEB-INF/lib directory this can cause the kind of problem you're seeing. So, in short, make sure that the above directory contains the MyFaces JSF impl and ensure that you're not packaging another set of JSF jars in your ear.

--Peter

PeterMGoldsteina at 2007-7-13 19:07:37 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
what is thr url in your browser? i think the problem is with web.xmltry using *.faces instead of *.jsf in the url pattern one more try is useyourpojectfolder /yourjsfile.faces
venkata.sriharshaa at 2007-7-13 19:07:37 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

Hi

You should rename your blank.jsp to blank.jsf

to ensure it matches your servlet-mapping as you have in your web.xml "*.jsf"

<servlet-mapping>

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

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

</servlet-mapping>

ArtiPandea at 2007-7-13 19:07:37 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
Hey PeterI will try this at once....Ralph
ralphmichelsena at 2007-7-13 19:07:37 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7

Hallo again Peter

You are a star !!!!!!! ;-)

This solved the problem. My faces .jar files in web-inf/lib was not the same as the ones in jbossweb-tomcat55.sar/jsf-lib.

When I copied the same faces jars to web-inf/lib the there were no errors.

THANK YOU VERY MUCH. You have been a huge help.

Regards Ralph

ralphmichelsena at 2007-7-13 19:07:37 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8

Ralph,

Glad I was able to help.

BTW, you don't even need to have the JSF/MyFaces jar files in your WEB-INF/lib. JBoss' classloader will load them from the jsf-libs directory in deploy/jbossweb-tomcat55.sar. This is the setup I use, and it helps minimize class collision problems. The only possible issue is that you have to include a reference to this JBOSS_HOME subdirectory in your build.xml, but this is fairly straightforward. See any of the JBoss sample apps that use JSF for a concrete example.

Regards,

Peter

PeterMGoldsteina at 2007-7-13 19:07:37 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 9

Hello, Good day.

By the way, Which IDE u are using?

And what you would suggest me, which have better design view support with other functionality for JSF development on JBOSS?

I am asking u this bcoz you are using JBOSS and there are some IDEs which doesnt directly support JBOSS (like sun Creator 2), or it might be i dont know, if it does. So please help me out.

Have a nice day.

Asif Shahzad

asifSh7a at 2007-7-13 19:07:37 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...