3

How can I use a JSF page as welcome file? The FacesServlet is mapped on *.jsf and the <welcome-file> is set to index.xhtml. However, it does not show the JSF components. I tried to set the <welcome-file> to index.jsf, but this results in a HTTP 404 error.

I'm using Tomcat 6.0 and JSF 2.1.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
maks
  • 5,911
  • 17
  • 79
  • 123
  • Your initial question was hard to cipher. I clarified this. I've also removed the second question about implicit navigation, you should actually ask this as another question. – BalusC Aug 10 '11 at 18:21

2 Answers2

6

Just rename <welcome-file> entry of index.xhtml to index.jsf and create an empty index.jsf file next to index.xhtml to fool the container that the file actually exist.

Alternatively, you can also just get rid of the .jsf extension altogether and use .xhtml all the way. This can be done by changing <url-pattern> of FacesServlet from *.jsf to *.xhtml.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • *Just rename entry of index.xhtml to index.jsf.* if i rename that entry i will not be able to have access to welcome page through context path(/testjsf), but only through /testjsf/index.jsf – maks Aug 10 '11 at 18:19
  • 1.Fooling the container by creating empty index.jsf works, but is it really good way to solve the problem? 2.Changing to *.xhtml will not allow me to use any extension that I want. – maks Aug 10 '11 at 18:29
  • 1) It's the easiest way, yes. 2) I don't see why that's a problem. It hides the implementation detail away and also prevents endusers of being able to see JSF source code when they manually change URL in browser address bar from .jsf to .xhtml. – BalusC Aug 10 '11 at 18:34
  • I'm trying this in Wildfly 8.2.0.Final but it does not seem to be working. When I start the app, it tries to open index.jsf. Any ideas? – K.Nicholas Dec 09 '14 at 18:22
3

Adding it to your welcome-file-list like this:

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

Does work, but you'll need Tomcat 7.

Another approach which also works with Tomcat 6 is adding a file called index.jsp with the following contents:

<jsp:forward page="/index.jsf"/>
Cristan
  • 12,083
  • 7
  • 65
  • 69