用于facelets模板和客户端的web.xml设置 [英] web.xml setup for facelets template and client
问题描述
我已经查看了一些有关JSF和facelets的资源,但不了解一些配置要点.之间的区别是什么
I've looked at a few resources for JSF and facelets, but don't understand a few configuration points. What's the distinction between:
<url-pattern>/faces/*</url-pattern>
和:
<url-pattern>*.jsf</url-pattern>
虽然我知道可能有几个url-pattern
元素,除非显式使用了.jsf页面,对映射没有实际需求,对吗?如果仅使用面孔模板和客户端,那是多余的吗?
While I understand it's possible to have several url-pattern
elements, unless .jsf pages are explicitly being used, there's no actual need for this mapping, correct? If only faces templates and clients are being used, then it's extraneous?
此外,如果facelet模板和客户端位于WEB-INF
内部,则如何访问它们?
Furthermore, if the facelet template and client are inside WEB-INF
, how are they accessed?
在JSF和Facelets的最新发行版中,faces-config.xml
似乎没有硬性要求.对吗?
With the latest releases for JSF and Facelets, there seems no hard requirement for faces-config.xml
; correct?
最后,如果将Glassfish与facelets客户端/模板一起使用,那么EL是通过CDI吗?
Finally, if Glassfish is being used with facelets clients/templates, then the EL is through CDI?
总体而言,为什么没有此客户端:
Overall, why isn't this client:
<?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:
with this 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仅在页面中这样显示:
Instead, the EL simply shows in the page as so:
thufir@dur:~$
thufir@dur:~$ 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>thufir@dur:~$
thufir@dur:~$
thufir@dur:~$ lynx http://localhost:8080/HelloExpressionLanguage/ -dump
top
expression language not evaluating?
thufir@dur:~$
thufir@dur:~$
推荐答案
目前尚不清楚您希望在哪里看到预期的"hello fred"输出. 在该示例中,您使用ui:insert,但将其用于模板.
It is not clear that where do you want to see the expected "hello fred" output. In the example you use ui:insert, but it for templates.
如果要在Bean中使用hello方法,则需要使用EL表达式,并为输出使用h:outputLabel标记:
if you want to use the hello method in the bean you will need to use an EL expression and for the output a h:outputLabel tag:
<h:outputLabel value="#{helloWorld.hello('fred')}" />
Update1(如果未处理JSF代码):
您应该检查您的web.xml.它必须包含一个servlet和一个这样的侦听器:
You should check your web.xml. It have to contains a servlet and a listener like this:
<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>*.jsf</url-pattern>
</servlet-mapping>
注意:使用.xhtml或.hello或其他方法时,必须匹配服务器映射的url模式.
Note: of you use .xhtml or .hello or something else, you have to match the url-pattern of the server-mapping.
这篇关于用于facelets模板和客户端的web.xml设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!