3

I am learning JSF and got help from Exadel.com. I followed the steps described there.

The web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    id="WebApp_ID" version="2.5">
    <display-name>FBApp</display-name>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
    <context-param>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>server</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>

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

    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>
</web-app>

faces-config.xml:

<?xml version="1.0" encoding="UTF-8"?>

<faces-config 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-facesconfig_1_2.xsd"
    version="1.2">

    <navigation-rule>
        <from-view-id>/pages/inputname.jsf</from-view-id>
        <navigation-case>
            <from-outcome>greeting</from-outcome>
            <to-view-id>/pages/greeting.jsf</to-view-id>
        </navigation-case>
    </navigation-rule>
    <managed-bean>
        <managed-bean-name>personBean</managed-bean-name>
        <managed-bean-class>com.fbapp.bean.PersonBean</managed-bean-class>
        <managed-bean-scope>request</managed-bean-scope>
    </managed-bean>

</faces-config>

index.jsp:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>index</title>
</head>
<body>
    <jsp:forward page="faces/pages/inputname.jsf" />
</body>
</html>

inputname.jsp:

<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<html>
 <head>
  <title>enter your name page</title>
 </head>
 <body>
   <f:view>
     <h1>
      <h:outputText value="JSF KickStart"/>
     </h1>
     <h:form id="helloForm">
      <h:outputText value="Tell us your name"/>
      <h:inputText value="#{personBean.personName}" />
      <h:commandButton action="greeting" value="Say Hello" />
     </h:form>
   </f:view>
 </body>
</html>  

Now the difference present is:

  • In index.jsp I used <jsp:forward page="faces/pages/inputname.jsf" /> and Exadel used <jsp:forward page="/pages/inputname.jsf" />
  • I have used <url-pattern>/faces/*</url-pattern> and they used : <url-pattern>*.jsf</url-pattern>

The jar libraries are:

  • commons-beanutils-1.7.0.jar
  • commons-codec-1.3.jar
  • commons-collections-3.1.jar
  • commons-digester-1.7.jar
  • commons-el-1.0.jar
  • commons-fileupload-1.0.jar
  • commons-lang-2.1.jar
  • commons-logging-1.0.4.jar
  • commons-validator-1.1.4.jar
  • jsf-api-1.2.jar
  • jsf-impl-1.2-NIGHTLY_20060227.jar
  • jstl-1.1.2.jar
  • oro-2.0.8.jar
  • xml-apis-1.0.b2.jar

In JBoss 4.2.2GA (customised for JSF) I deployed the war its running but when I am trying to go to the url http://localhost:8080/FBApp/ the page is rendered as:

ERROR

which is actually the code of inputname.jsf. What I am doing wrong? Any information will be appreciable.

Thanks and regards.


Edit: Code changed as instructed by BalusC. Now I am getting exception and the stacktrace:

19:34:04,244 ERROR [[jsp]] Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
    at com.sun.faces.taglib.jsf_core.ViewTag.doStartTag(ViewTag.java:162)
    at org.apache.jsp.pages.inputname_jsp._jspx_meth_f_005fview_005f0(inputname_jsp.java:104)
    at org.apache.jsp.pages.inputname_jsp._jspService(inputname_jsp.java:77)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:336)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:654)
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:445)
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:379)
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:292)
    at org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:694)
    at org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:665)
    at org.apache.jsp.index_jsp._jspService(index_jsp.java:63)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:336)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
    at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
    at java.lang.Thread.run(Thread.java:636)
19:34:04,245 ERROR [[jsp]] Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
    at com.sun.faces.taglib.jsf_core.ViewTag.doStartTag(ViewTag.java:162)
    at org.apache.jsp.pages.inputname_jsp._jspx_meth_f_005fview_005f0(inputname_jsp.java:104)
    at org.apache.jsp.pages.inputname_jsp._jspService(inputname_jsp.java:77)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:336)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:654)
    at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:445)
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:379)
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:292)
    at org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:694)
    at org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:665)
    at org.apache.jsp.index_jsp._jspService(index_jsp.java:63)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:336)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
    at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
    at java.lang.Thread.run(Thread.java:636)
Community
  • 1
  • 1
Tapas Bose
  • 28,796
  • 74
  • 215
  • 331
  • This usually means that JBoss is not parsing/compiling your source code. Do other test projects work? – Jacob Jul 24 '11 at 13:48
  • @cularis This is my first project actually. I was getting `java.lang.ClassCastException: com.sun.faces.application.ApplicationAssociate cannot be cast to com.sun.faces.application.ApplicationAssociate` and I found a solution of this problem [here](http://dushyants.blogspot.com/2009/01/error-running-jsf-with-jboss.html) and did it as said and the problem was solved. I am using JBoss 4.2.2 with JSF 1.2. – Tapas Bose Jul 24 '11 at 13:55

2 Answers2

8

This can happen if you gave your actual JSP files a .jsf extension. In other words, you don't have a inputname.jsp file in your web content folder, but actually a inputname.jsf file. This is Wrong. Those JSP files should keep their .jsp extension in order to get processed by the JspServlet. Otherwise those files won't be parsed as JSP at all and will end up as plain text in the webbrowser.

You have changed the URL pattern of the FacesServlet to be /faces/* instead of (the more recommended) *.jsf. So you should change all URLs in the tutorial from /foo.jsf to /faces/foo.jsp, also in the forwards/includes and navigation cases. You should not change to /faces/foo.jsf and use the wrong extension in the actual files.


Unrelated to the concrete problem: is there any particular reason that you're reading a 6 year old JSF 1.1 targeted tutorial instead of a more recent JSF 2.0 targeted tutorial? JSF 1.1 has so many disadvantages and also the legacy JSP has been succeeded by Facelets since 1.5 years ago.


Update as per the comment on the question:

@cularis This is my first project actually. I was getting java.lang.ClassCastException: com.sun.faces.application.ApplicationAssociate cannot be cast to com.sun.faces.application.ApplicationAssociate and I found a solution of this problem here and did it as said and the problem was solved. I am using JBoss 4.2.2 with JSF 1.2

This exception can occur if the runtime classpath is polluted with different versioned JSF libraries. JBoss ships with JSF builtin already, so you should not be providing JSF libraries in webapp's /WEB-INF/lib folder. If it's of a different version, it will likely collide with exceptions like above.


Update 2 as per the question update:

java.lang.NullPointerException
    at com.sun.faces.taglib.jsf_core.ViewTag.doStartTag(ViewTag.java:162)

Well, this is a nasty one and I haven't seen it before. I'll bet it to be caused by just a classpath pollution. JBoss 4.2.x ships with JSF 1.2 and JSTL 1.1 already builtin. Please remove jsf*.jar and jstl*.jar libraries from /WEB-INF/lib. Please also remove all JSF-related <context-param> and <listener> entires from web.xml. The ones which you've as far are all the JSF 1.2 default already. It may or may not solve your concrete problem, but it should at least minimize the noise. Let me know.


Update 3 as per the comments:

I have removed the jars and the entries from web.xml and also uncomment the commented line in jboss-4.2.2.GA/server/default/deploy/jboss-web.deployer/conf/web.xml and now I am getting java.lang.RuntimeException: Cannot find FacesContext. But the previous problem is solved

Much better. The Cannot find FacesContext error has an easy cause: the FacesServlet hasn't been invoked. So the request or forward URL didn't match the URL pattern of the FacesServlet at all. Assuming that you have still mapped your FacesServlet on an URL pattern of /faces/* and that you have a physical /pages/inputname.jsp file in your web content, then all your index.jsp should contain is the following single line (yes, get rid of all that irrelevant HTML as well)

<jsp:forward page="faces/pages/inputname.jsp" />

This way just calling

http://localhost:8080/FBApp/

should work. If it doesn't for some reason (let me know) then at least calling

http://localhost:8080/FBApp/faces/pages/inputname.jsp

must work.


Update 4 as per the comments:

The FacesContext exception is solved but now it is throwing javax.faces.FacesException: java.net.MalformedURLException: Path faces-config.xml does not start with a "/" character.

Hmm, this is also new to me. How does your web.xml now look like? This suggests that you've a javax.faces.CONFIG_FILES context param with a wrong value of faces-config.xml. Try putting the javax.faces.CONFIG_FILES context param with value of /WEB-INF/faces-config.xml back in the web.xml. Perhaps the JSF 1.2 impl used in JBoss has some bug related to this.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • thank you very much for your suggestion and I will take steps as said. But in the current scenario I am using JSF 1.2 and latter I will go to JSF 2.0. I have added an exception stack-trace in my original post, can you help me to find the solution? – Tapas Bose Jul 24 '11 at 14:14
  • I have removed the jars and the entries from web.xml and also uncomment the commented line in jboss-4.2.2.GA/server/default/deploy/jboss-web.deployer/conf/web.xml and now I am getting `java.lang.RuntimeException: Cannot find FacesContext`. But the previous problem is solved. – Tapas Bose Jul 24 '11 at 14:32
  • The `FacesContext` exception is solved but now it is throwing `javax.faces.FacesException: java.net.MalformedURLException: Path faces-config.xml does not start with a "/" character`. – Tapas Bose Jul 24 '11 at 14:50
1

If you are a starter, you should really start reading JSF 2.0 and not the old deprecated 1.1. There are a lots of books related to JSF. Bests

dan
  • 74
  • 1