1
votes

I have created a new Maven web application in eclipse, and it gave me a Hello World example written in a file named index.jsp located in src/main/webapp.

Let's say I have created a facelet (login.xhtml) and I want my application to run it as default page, instead of the index.jsp page.

I would like to know how and where to change the default value of the file which is lanched.

Thanks in advance.

1

1 Answers

0
votes

First of all, you need add support to JSF (maybe not) and facelets in your project if you.

<!-- JSF -->
<dependency>
    <groupId>com.sun.faces</groupId>
    <artifactId>jsf-api</artifactId>
    <version>${jsf.version}</version>
</dependency>
<dependency>
    <groupId>com.sun.faces</groupId>
    <artifactId>jsf-impl</artifactId>
    <version>${jsf.version}</version>
</dependency>

<dependency>
    <groupId>com.sun.facelets</groupId>
    <artifactId>jsf-facelets</artifactId>
    <version>${facelets.version}</version>
</dependency>

You can just add a facelets library, such as Prime Faces.

Config your web.xml, add something like this:

<!-- 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>

<!-- Use Documents Saved as *.xhtml --> 
<context-param>
    <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
    <param-value>.xhtml</param-value>
</context-param>

<!-- Special Debug Output for Development -->
<context-param>
    <param-name>facelets.DEVELOPMENT</param-name>
    <param-value>true</param-value>
</context-param>

After this, you'll need change welcome-file-list in your web.xml:

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

If you are using facelets, so you'll need to create a faces-config.xml file, like this:

<faces-config>      
    <application>
        <view-handler>com.sun.facelets.FaceletViewHandler</view-handler>    
    </application> 
</faces-config>

Read more about here.