今天看了一下Facelets。感覺組件化的概念比較強了。配置文件好象也比T itle少了。
經過一下午的測試,覺得還是不在項目使用了,但是要把經過記一下。
- 在官網下載最新JAR包。雖然是最新的也要2006年呢。并把它放到WEB-INF/lib中
- 在WEB.xml中加入
<view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
JavaServer Faces默認使用JSP文件定義視圖(*.jsp)。在WEB-INF/web.xml中修改該類型。
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
?
這段代碼是在出現Requires FaceletFilter to be initialized with Application!!這個錯誤時加入到web.xml中的。(找了好長好長時間啊!)
<filter>
????<filter-name>facelets</filter-name>
????<filter-class>
????????com.sun.facelets.webapp.FaceletFilter
????</filter-class>
</filter>
<filter-mapping>
????<filter-name>facelets</filter-name>
????<url-pattern>*.xhtml</url-pattern>
</filter-mapping>
?
然后寫一個XHTML文件就可以用了。注意所有的JSP文件都要換成XMHTL
<html xmlns="http://www.w3.org/1999/xhtml"
????xmlns:h="http://java.sun.com/jsf/html"
????xmlns:f="http://java.sun.com/jsf/core">
????<head>
????????<meta http-equiv="Content-Type"
????????????content="text/html; charset=iso-8859-1" />
????????<title>My First Facelet</title>
????</head>
????<body>
????????<!-- body content goes here -->
????????<f:view>
????????????<h:outputText value="#{UserBean.userId}"></h:outputText>
????????</f:view>
????</body>
</html>
?
這篇文章只是作個記號!
posted on 2007-05-25 15:46
Libo 閱讀(1351)
評論(0) 編輯 收藏