1

I want to create JSF 2.0 project in Eclipse 3.6 and I want to deploy it on Websphere Application Server Community Edition 2.1.

I created a simple web project.

And in index.html I write this code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
 xmlns:h="http://java.sun.com/jsf/html"
 xmlns:f="http://java.sun.com/jsf/core"
 xmlns:ui="http://java.sun.com/jsf/facelets">

<h:head>
 <title>JSF 2.0</title>
</h:head>
<h:body>
jsf welcome
</h:body>
</html>

But the text between <h:body> and <h:body> tags can not be seen in the page. How can I solve this problem?

This is buildpath:

enter image description here

And this is the web.xml file

<?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>JSFApp</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <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>
  <context-param>
    <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>client</param-value>
  </context-param>
  <context-param>
    <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
    <param-value>resources.application</param-value>
  </context-param>
  <listener>
    <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
  </listener>
</web-app>

Is there any mistake ?

4
  • Try adding facet for JSF 2.0 from the project settings. If nothing else that would add you helpful validations.
    – erloewe
    Feb 10, 2011 at 19:16
  • @erloewe: The facet is likely already added considering the JSF entry in the Libraries screenshot and the (poor) Eclipse-default /faces/* url pattern in web.xml.
    – BalusC
    Feb 10, 2011 at 20:08
  • @Balusc Those things were added to the question after I was around :) Just making sure, just making sure... Nice answer by the way.
    – erloewe
    Feb 10, 2011 at 20:39
  • @erloewe: Oh sorry, I now see the timestamps. Thank you :)
    – BalusC
    Feb 10, 2011 at 20:47

1 Answer 1

2

There are 2 problems:

  1. You're using .html instead of .xhtml. JSF 2.0 by default resolves views on *.xhtml. Rename your index.html to index.xhtml.

  2. You should open the page in browser by an URL matching the url-pattern of the FacesServlet, which is /faces/* in your case. Thus so: http://example.com/contextname/faces/index.xhtml and not so http://example.com/contextname/index.xhtml and even not .html.

    However, I'd recommend to replace /faces/* by *.xhtml so that you (and your endusers) don't need to be surprised when omitting or forgetting the /faces part in the URL. The only disadvantage is that you won't be able to serve "plain vanilla" .xhtml files without involvement of FacesServlet, but this is almost never the case in real world. Rather just serve such files as .html then.

See also:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.