A JSF application needs on the following two configuration files:
1. web.xml
2. faces-config.xml
Note: Put the configuration files under WEB-INF folder.
web.xml:
Example:
<?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0" 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-app_3_0.xsd"> <servlet> <servlet-name>faces</servlet-name> <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>faces</servlet-name> <url-pattern>/faces/*</url-pattern> </servlet-mapping> </web-app> |
faces-config.xml:
The faces-config.xml file contains the JSF application configuration. It can be used to configure the following:
1. Used to configure managed beans.
2. Used to configure convertors.
3. Used to configure validators.
4. Used to configure navigation.
Example:
<?xml version="1.0" encoding="windows-1252"?> <faces-config version="2.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xi="http://www.w3.org/2001/XInclude" 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_2_0.xsd"> <navigation-rule> <from-view-id>helloworld.xhtml</from-view-id> <navigation-case> <from-outcome>success</from-outcome> <to-view-id>welcome.xhtml</to-view-id> </navigation-case> <navigation-case> <from-outcome>fail</from-outcome> <to-view-id>helloworld.xhtml</to-view-id> </navigation-case> </navigation-rule> |