我已经看过JSF和facelets的一些资源,但不明白一些配置点。什么是之间的区别:facelets模板和客户端的web.xml设置
<url-pattern>/faces/*</url-pattern>
和:
<url-pattern>*.jsf</url-pattern>
虽然我知道这是可能有若干个url-pattern
元素,除非明确地使用.jsf页,有这种映射没有实际需要,正确?如果只有模板和客户端正在使用,那么它是无关的?
此外,如果facelet模板和客户端在WEB-INF
之内,它们是如何访问的?
对于JSF和Facelets的最新版本,似乎没有硬性要求faces-config.xml
;正确?
最后,如果Glassfish与facelets客户端/模板一起使用,那么EL是通过CDI?
总体而言,为什么不是这样的客户:
<?xml version='1.0' encoding='UTF-8' ?>
<!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://xmlns.jcp.org/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<body>
<ui:composition template="./template.xhtml">
<ui:define name="top">
top
</ui:define>
<ui:define name="content">
expression language not evaluating?
<h:outputLabel value="#{hello.hi(fred)}" />
</ui:define>
</ui:composition>
</body>
</html>
使用该模板:
<?xml version='1.0' encoding='UTF-8' ?>
<!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://xmlns.jcp.org/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<h:outputStylesheet name="./css/default.css"/>
<h:outputStylesheet name="./css/cssLayout.css"/>
<title>Facelets Template</title>
</h:head>
<h:body>
<div id="top" class="top">
<ui:insert name="top">Top</ui:insert>
</div>
<div id="content" class="center_content">
<ui:insert name="content">Content</ui:insert>
</div>
</h:body>
</html>
这个web.xml中:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<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>/faces/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>faces/client.xhtml</welcome-file>
</welcome-file-list>
</web-app>
使用这个bean:
package pkg;
import javax.faces.bean.SessionScoped;
import javax.inject.Named;
@Named
@SessionScoped
public class Hello {
public Hello() {
}
public String hi(String name) {
return "hi " + name;
}
}
相反,EL只显示在页面像这样:
[email protected]:~$
[email protected]:~$ lynx http://localhost:8080/HelloExpressionLanguage/client.xhtml -dump
<?xml version='1.0' encoding='UTF-8' ?>
<!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://xmlns.jcp.org/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<body>
<ui:composition template="./template.xhtml">
<ui:define name="top">
top
</ui:define>
<ui:define name="content">
expression language not evaluating?
<h:outputLabel value="#{hello.hi(fred)}" />
</ui:define>
</ui:composition>
</body>
</html>[email protected]:~$
[email protected]:~$
[email protected]:~$ lynx http://localhost:8080/HelloExpressionLanguage/ -dump
top
expression language not evaluating?
[email protected]:~$
[email protected]:~$
为什么'ui:insert'用于模板?这个例子当然使用了模板,所以我不明白你在做什么。使用'ui:insert'是不正确的? – Thufir 2014-10-29 13:15:19