views:

86

answers:

1

This is the structure of my project (exactly these five files):

/p1
  pom.xml
  /src
    /main
      /java
      /webapp
        a.html
        b.xhtml
      /WEB-INF
        faces-config.xml
        web.xml

I'm deploying this WAR to GlassFish and I can successfully access this URL: http://localhost:8080/p1/a.html. When I'm trying to open http://localhost:8080/p1/b.xhtml I'm getting a message

The requested resource (/p1/b.xhtml) is not available.

What am I doing wrong?

ps. My dependencies from pom.xml:

...
<dependency>
  <groupId>com.sun.faces</groupId>
  <artifactId>jsf-api</artifactId>
  <version>${jsf.version}</version>
  <scope>provided</scope>
</dependency>
<dependency>
  <groupId>com.sun.faces</groupId>
  <artifactId>jsf-impl</artifactId>
  <version>${jsf.version}</version>
  <scope>provided</scope>
</dependency>
<dependency>
  <groupId>com.sun.facelets</groupId>
  <artifactId>jsf-facelets</artifactId>
  <version>${facelets.version}</version>
</dependency>
...

This is my web.xml (core part of it):

<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>*.xhtml</url-pattern>
</servlet-mapping>

My faces-config.xml:

<application>
  <view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
</application>
+2  A: 

For the Maven side, things looks ok, except that facelets should also be provided. Actually, I use the following dependency:

<!-- This dependency will bring in everything we need for JAVA EE6 -->
<dependency>
  <groupId>javax</groupId>
  <artifactId>javaee-api</artifactId>
  <version>6.0</version>
  <scope>provided</scope>
</dependency>

For the JSF part, nothing in the server logs? Just in case, could you add the following to your web.xml to see if you get more useful output:

<context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Development</param-value>
</context-param>

As a side note, you don't need your faces-config.xml as Facelets is the default view handler in JSF 2.0. But this shouldn't be a problem.

PS: Personally, I prefer to map the Faces Servlet on something like *.jsf (to clearly de-correlate any mapped url from the actual .xhtml facelet page that will be processed by the Faces Servlet).

See also

Pascal Thivent
I've done everything you suggested (stage, removal of `faces-config.xml` and `.jsf` instead of `.xhtml`) and it works! :) Many thanks!
Vincenzo
The reason that `faces-config.xml` is not needed due to Facelets is not fully true. You would still need it in JSF 1.2 + Facelets. It's just not needed for bean definitions and navigation cases in JSF 2.0 thanks to new JSF 2.0 support for annotations (managed beans) and convention-over-configuration (navigation outcomes).
BalusC