8 Replies Latest reply on Nov 9, 2009 5:04 AM by ilya_shaikovsky

    java.lang.NullPointerException: FacesContext is null when us

    webera

      Hi all,

      i have a problem using a4j:include. Here are the first few lines of the Exception I get when it comes to the page using a4j:include (When I copy the content directly in the page it works without problems):

      java.lang.NullPointerException: FacesContext is null
       at org.ajax4jsf.context.AjaxContext.getCurrentInstance(AjaxContext.java:159)
       at org.ajax4jsf.context.AjaxContext.getCurrentInstance(AjaxContext.java:144)
       at org.ajax4jsf.component.AjaxViewRoot.getViewId(AjaxViewRoot.java:583)
       at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:104)
       at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
       at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
       at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
       at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)
       at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
      


      Perhaps I miss something in the web.xml?

      <?xml version="1.0"?>
      <web-app version="2.5"
       xmlns="http://java.sun.com/xml/ns/javaee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
      <display-name>stdplan</display-name>
      
      <context-param>
       <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
       <param-value>server</param-value>
      </context-param>
      
      <context-param>
       <param-name>org.richfaces.SKIN</param-name>
       <param-value>blueSky</param-value>
      </context-param>
      
      <context-param>
       <param-name>org.richfaces.CONTROL_SKINNING</param-name>
       <param-value>enable</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>
      
      
      <listener>
       <listener-class>com.sun.faces.config.ConfigureListener</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>
      
      </web-app>
      



        • 1. Re: java.lang.NullPointerException: FacesContext is null whe
          nbelaevski

          Hi,

          Please provide the following information:
          - JSF version
          - Facelets or JSP

          • 2. Re: java.lang.NullPointerException: FacesContext is null whe
            webera

            Hi,

            - I use JBoss 5.1.0.GA with Mojarra (1.2_12-b01-FCS).
            - Its a jsp page

            Thats the content of the page

            <!doctype html public "-//w3c//dtd html 4.0 transitional//en">
            <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
            <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
            <!-- RichFaces tag library declaration -->
            <%@ taglib uri="http://richfaces.org/a4j" prefix="a4j" %>
            <%@ taglib uri="http://richfaces.org/rich" prefix="rich" %>
            
            <html>
             <head>
             <title>Stdplan</title>
             </head>
             <body>
             <f:view>
             <a4j:form>
             <rich:toolBar>
             <!-- toolbar Content -->
             </rich:toolBar>
            
             <a4j:include viewId="/prof.jsf"/>
             </a4j:form>
             </f:view>
             </body>
            </html>
            


            • 3. Re: java.lang.NullPointerException: FacesContext is null whe
              nbelaevski

              Use .jsp not .jsf:

              <a4j:include viewId="/prof.jsp"/>


              • 4. Re: java.lang.NullPointerException: FacesContext is null whe
                webera

                Then I get this exception

                javax.servlet.ServletException: javax.servlet.jsp.JspException: org.apache.jasper.JasperException: /prof.jsp(4,27) #{..} is not allowed in template text
                 org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:848)
                 org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:781)
                 org.apache.jsp.index_jsp._jspService(index_jsp.java:96)
                 org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
                 javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
                 org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
                 org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:322)
                 org.apache.jasper.servlet.JspServlet.service(JspServlet.java:249)
                 javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
                


                Now the request is no longer handled by the FacesServlet what causes this exception i think.
                I have a rich:dataTable in the jsp file which should also be processed via FacesServlet:

                 <rich:dataTable value="#{profs.profList}" var="prof">
                 <!-- table code -->
                 </rich:dataTable>
                


                • 5. Re: java.lang.NullPointerException: FacesContext is null whe
                  nbelaevski

                  You have syntax error in JSP file, that's why JasperException occurs.

                  • 6. Re: java.lang.NullPointerException: FacesContext is null whe
                    webera

                    But if i only copy the content from prof.jsp to index.jsp instead of the a4j:include everything works fine - the datatable is displayed

                    <!doctype html public "-//w3c//dtd html 4.0 transitional//en">
                    <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
                    <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
                    <!-- RichFaces tag library declaration -->
                    <%@ taglib uri="http://richfaces.org/a4j" prefix="a4j" %>
                    <%@ taglib uri="http://richfaces.org/rich" prefix="rich" %>
                    
                    <html>
                     <head>
                     <title>Stdplan</title>
                     </head>
                     <body>
                     <f:view>
                     <a4j:form>
                     <rich:toolBar>
                     <!-- toolbar Content -->
                     </rich:toolBar>
                    
                     <!-- data table is display without errors -->
                     <rich:dataTable value="#{profs.profList}" var="prof">
                     <!-- table code -->
                     </rich:dataTable>
                    
                    
                     </a4j:form>
                     </f:view>
                     </body>
                    </html>
                    


                    • 7. Re: java.lang.NullPointerException: FacesContext is null whe
                      webera

                      I open the page this way

                      http://localhost:8080/stdplan/index.jsf
                      



                      • 8. Re: java.lang.NullPointerException: FacesContext is null whe
                        ilya_shaikovsky

                        show please full included page code.