You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Daniel <pd...@gmail.com> on 2008/08/16 22:37:20 UTC

Cannot find FacesContext at javax.faces.webapp

Hello, i have a problem loading my jsf pages (i am using richfaces).

I am using jetty server, as maven plugin... Also i have made a test, a
classic one loading inputme, and greetings. When i had forward my index to
that pages it worked without any problems.

I am trying to include a page in another like this :

<%@include file="/pages/navigation/navigation.jsf"%>

my navigation page :

<%@ include file="/taglibs.jsp" %>
<a4j:page>
<h:form>
<rich:toolBar>
<rich:dropDownMenu>
<f:facet name="label">
<h:panelGroup>
<h:graphicImage value="/images/icons/copy.gif" styleClass="pic"/>
<h:outputText value="File"/>
</h:panelGroup>
</f:facet>
<rich:menuItem submitMode="ajax" value="New"
action="#{ddmenu.doNew}" icon="/images/icons/create_doc.gif">
</rich:menuItem>
<rich:menuItem submitMode="ajax" value="Open"
action="#{ddmenu.doOpen}" icon="/images/icons/open.gif"/>
<rich:menuGroup value="Save As...">
<rich:menuItem submitMode="ajax" value="Save"
action="#{ddmenu.doSave}" icon="/images/icons/save.gif"/>
<rich:menuItem submitMode="ajax" value="Save All"
action="#{ddmenu.doSaveAll}">
<f:facet name="icon">
<h:graphicImage value="/images/icons/save_all.gif"/>
</f:facet>
</rich:menuItem>
</rich:menuGroup>
<rich:menuItem submitMode="ajax" value="Close"
action="#{ddmenu.doClose}"/>
<rich:menuSeparator id="menuSeparator11"/>
<rich:menuItem submitMode="ajax" value="Exit"
action="#{ddmenu.doExit}"/>
</rich:dropDownMenu>
<rich:dropDownMenu>
<f:facet name="label">
<h:panelGrid cellpadding="0" cellspacing="0" columns="2"
style="vertical-align:middle">
<h:outputText value="Links"/>
</h:panelGrid>
</f:facet>
<rich:menuItem submitMode="none"
onclick="document.location.href='http://labs.jboss.com/jbossrichfaces/'">
<h:outputLink value="http://labs.jboss.com/jbossrichfaces/">
<h:outputText value="RichFaces Home Page"></h:outputText>
</h:outputLink>
</rich:menuItem>
<rich:menuItem submitMode="none"
onclick="document.location.href='
http://jboss.com/index.html?module=bb&amp;op=viewforum&amp;f=261'">
<h:outputLink
value="http://jboss.com/index.html?module=bb&amp;op=viewforum&amp;f=261">
<h:outputText value="RichFaces Forum"></h:outputText>
</h:outputLink>
</rich:menuItem>
</rich:dropDownMenu>
</rich:toolBar>
</h:form>
<rich:spacer width="1" height="5" />
<br/>
<a4j:outputPanel ajaxRendered="true">
<h:outputText value="Current Selection: "></h:outputText>
<h:outputText style="font-weight:bold"
value="#{ddmenu.current}"></h:outputText>
</a4j:outputPanel>
<br/>
<rich:spacer width="1" height="25" />
</a4j:page>


my taglibs page :

<%@ page language="java" errorPage="/error.jsp" pageEncoding="UTF-8"
contentType="text/html;charset=utf-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://richfaces.org/a4j" prefix="a4j"%>
<%@ taglib uri="http://richfaces.org/rich" prefix="rich"%>
<%@ taglib uri="http://www.opensymphony.com/sitemesh/decorator"
prefix="decorator" %>
<%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%>

<c:set var="datePattern"><fmt:message key="date.format"/></c:set>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>


and my web.xml

<?xml version="1.0"?>
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<!-- Define the basename for a resource bundle for I18N -->
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>messages</param-value>
</context-param>

<!-- From http://wiki.apache.org/myfaces/Performance -->
<!--Server side state saving performs better: -->
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>

<!-- Next step - disable compression of state in server: -->
<context-param>
<param-name>org.apache.myfaces.COMPRESS_STATE_IN_SESSION</param-name>
<param-value>false</param-value>
</context-param>

<!-- Very important, too, is to disable the serialization of state,
serialization and deserialization of the component tree is a major
performance hit. -->
<context-param>
<param-name>org.apache.myfaces.SERIALIZE_STATE_IN_SESSION</param-name>
<param-value>false</param-value>
</context-param>

<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>/WEB-INF/faces-config.xml</param-value>
</context-param>

<context-param>
<param-name>org.richfaces.SKIN</param-name>
<param-value>blueSky</param-value>
</context-param>

<filter>
<display-name>RichFaces Filter</display-name>
<filter-name>richfaces</filter-name>
<filter-class>org.ajax4jsf.Filter</filter-class>
</filter>

<filter-mapping>
<filter-name>richfaces</filter-name>
<servlet-name>Faces Servlet</servlet-name>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>

<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>

<filter>
<filter-name>lazyLoadingFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>

<filter>
<filter-name>sitemesh</filter-name>
<filter-class>com.opensymphony.module.sitemesh.filter.PageFilter</filter-class>
</filter>


<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext*.xml</param-value>
</context-param>

<context-param>
<param-name>facelets.LIBRARIES</param-name>
<param-value>
/WEB-INF/taglibs/tomahawk.taglib.xml
</param-value>
</context-param>

<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>

<!--<filter-mapping>
<filter-name>messageFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
</filter-mapping>-->

<filter-mapping>
<filter-name>lazyLoadingFilter</filter-name>
<url-pattern>*.html</url-pattern>
</filter-mapping>

<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

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

<!-- 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>

<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>

<error-page>
<error-code>404</error-code>
<location>/404.jsp</location>
</error-page>

<error-page>
<error-code>500</error-code>
<location>/error.jsp</location>
</error-page>

</web-app>

my arror is :

An Error has occurred in this application. java.lang.RuntimeException:
Cannot find FacesContext at
javax.faces.webapp.UIComponentClassicTagBase.getFacesContext(UIComponentClassicTagBase.java:1797)
at
javax.faces.webapp.UIComponentClassicTagBase.setJspId(UIComponentClassicTagBase.java:1614)
at
org.apache.jsp.decorators.default_jsp._jspx_meth_a4j_page_0(org.apache.jsp.decorators.default_jsp:530)
at
org.apache.jsp.decorators.default_jsp._jspService(org.apache.jsp.decorators.default_jsp:239)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:93) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:820) at
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:470)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:364) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:820) at
org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487) at
org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362) at
org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:726)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405) at
org.mortbay.jetty.servlet.Dispatcher.include(Dispatcher.java:192) at
com.opensymphony.module.sitemesh.filter.PageFilter.applyDecorator(PageFilter.java:156)
at
com.opensymphony.module.sitemesh.filter.PageFilter.doFilter(PageFilter.java:59)
at
org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084)
at
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)
at
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at
org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:360)
at
org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:726)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405) at
org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:206)
at
org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:324) at
org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505) at
org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:828)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:514) at
org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211) at
org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380) at
org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
at
org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:450)

Re: Cannot find FacesContext at javax.faces.webapp

Posted by simon <si...@chello.at>.
On Sat, 2008-08-16 at 23:37 +0300, Daniel wrote:
> Hello, i have a problem loading my jsf pages (i am using richfaces).
> 
> I am using jetty server, as maven plugin... Also i have made a test, a
> classic one loading inputme, and greetings. When i had forward my
> index to that pages it worked without any problems.
> 
> I am trying to include a page in another like this :

I don't think the problem is anything to do with the include.


> <filter-mapping>
> <filter-name>sitemesh</filter-name>
> <url-pattern>/*</url-pattern>
> <dispatcher>REQUEST</dispatcher>
> <dispatcher>FORWARD</dispatcher>
> </filter-mapping>
> 
> <listener>
> <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
> </listener>


> <!-- <listener>
> <listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
> </listener>-->
> 
> <!-- 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>


> 
> my arror is :
> 
> An Error has occurred in this application. java.lang.RuntimeException:
> Cannot find FacesContext at
> javax.faces.webapp.UIComponentClassicTagBase.getFacesContext(UIComponentClassicTagBase.java:1797)


>  at
> com.opensymphony.module.sitemesh.filter.PageFilter.applyDecorator(PageFilter.java:156) at com.opensymphony.module.sitemesh.filter.PageFilter.doFilter(PageFilter.java:59) at org.mortbay.jetty.servlet.ServletHandler


Firstly, you're running Sun's JSF implementation. We can't give you any
detailed help on that. But here's some possible pointers anyway:

In order for a JSF page to work, the request needs to execute the
FacesServlet. If it doesn't, then you get exactly this problem: no
FacesContext object gets created.

And your stacktrace shows clearly that the FacesServlet is not getting
executed.

You are using SiteMesh here. Combining SiteMesh with JSF is not easy. It
is almost certainly your use of SiteMesh here that is causing the jsp
page to run without having executed the FacesServlet.

I suggest you search the web for information on combining SiteMesh with
JSF. And if you have any followup questions, make sure you point out
that you are using SiteMesh; it makes a world of difference.

Regards,
Simon