简体   繁体   中英

How to make facelets work?

I have created a new web project and enabled its JSF and Facelets capabilities on MyEclipse, then I deployed it over weblogic. Everything look fine but it does not work for me, it seems that the view-handler is not called at all. What is wrong with it? Could anyone help me?

This is my web.xml :

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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_2_5.xsd">
    <context-param>
        <param-name>javax.faces.CONFIG_FILES</param-name>
        <param-value>/WEB-INF/faces-config.xml</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
        <param-value>.xhtml</param-value>
    </context-param>
    <context-param>
        <param-name>facelets.VIEW_MAPPINGS</param-name>
        <param-value>*.xhtml</param-value>
    </context-param>
    <context-param>
        <param-name>facelets.DEVELOPMENT</param-name>
        <param-value>true</param-value>
    </context-param>
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>0</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.faces</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>
</web-app>

And this is my faces-config.xml entry:

<application>
    <view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
    <locale-config>
        <default-locale>en</default-locale>
    </locale-config>
</application>

This is my simple xhtml :

<!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:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xml:lang="en" lang="en">
    <head>
        <title>My Facelets Page</title>
        <meta http-equiv="keywords" content="enter,your,keywords,here" />
        <meta http-equiv="description" content="A short description of this page." />
        <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
        <!--<link rel="stylesheet" type="text/css" href="styles.css">-->
    </head>
    <body>
        <p>
            <ui:insert name="body">This is my JavaServer Facelets page.</ui:insert>
        </p>
    </body>
</html>

This can happen if you don't request the page through the url-pattern of the FacesServlet . Ensure that your request URL is correct. Ie open the page by http://example.com/context/page.jsf and thus not by http://examlpe.com/context/page.xhtml .

If that doesn't help, then the firstnext step is to read the server logs for any errors or warnings.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM