在Eclipse生成的代码中页面是使用facelets、richFaces等编写的,所以页面使用的文件格式是xhtml。而非jsp。当然了,你也可以是用jsp编写。这些生成的xhtml全部都在WebContent下
   首先看home.xhtml。
    - <ui:composition xmlns="http://www.w3.org/1999/xhtml"
    
-                 xmlns:s="http://jboss.com/products/seam/taglib"
    
-                 xmlns:ui="http://java.sun.com/jsf/facelets"
    
-                 xmlns:f="http://java.sun.com/jsf/core"
    
-                 xmlns:h="http://java.sun.com/jsf/html"
    
-                 xmlns:rich="http://richfaces.org/rich"
    
-                 template="layout/template.xhtml">
    
- </ui:composition>
 
ui:composition元素:UI组件,使用这个元素做根元素表示这个页面并不是一个完整的页面,而是需要一个template页面作为摸版的内容页面。
        xmlns:根元素命名空间。就是那些不带前缀标签比如<div>
         xmlns:s:Seam元素的命名空间。
        template:摸版页面
摸版页面:
    - <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"
    
-       xmlns:s="http://jboss.com/products/seam/taglib">
    
- <head>
    
-     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    
-     <title>SeamTest</title>
    
-     <link href="stylesheet/theme.css" rel="stylesheet" type="text/css" />
    
- </head>
    
- 
    
- <body>
    
- 
    
-     <ui:include src="menu.xhtml">
    
-         <ui:param name="projectName" value="SeamTest"/>
    
-     </ui:include>
    
- 
    
-     <div class="body">
    
-         <ui:insert name="body"/>
    
-     </div>
    
- 
    
-     <div class="footer">
    
-         Powered by <a href="http://jboss.com/products/seam">Seam</a>.
    
-         Generated by seam-gen.
    
-     </div>
    
- 
    
- </body>
    
- </html>
 
ui:include:与<jsp:include>差不多。但这里没有引入jsp命名空间。所以使用<ui:include>。
<ui:insert/>:这个是一个template页面。这个标签表示插入一个名为body的内容块。在内容页面--home.xhtml--与此对应的是:<ui:define name="body"></ui:define>。在Seam-gen生成的页面中几乎所有的页面都将template指向template.xhtml。还有另一种使用摸板的方式。比如layout/edit.xhtml。
    - <ui:composition  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"
    
-                  xmlns:s="http://jboss.com/products/seam/taglib">
    
- 
    
-     <div class="prop">
    
- 
    
-         <s:label styleClass="name #{invalid?'errors':''}">
    
-             <ui:insert name="label"/>
    
-             <s:span styleClass="required" rendered="#{required}">*</s:span>
    
-         </s:label>
    
- 
    
-         <span class="value #{invalid?'errors':''}">
    
-             <s:validateAll>
    
-                 <ui:insert/>
    
-             </s:validateAll>
    
-         </span>
    
- 
    
-         <span class="error">
    
-             <h:graphicImage value="/img/error.gif" rendered="#{invalid}" styleClass="errors"/>
    
-             <s:message styleClass="errors"/>
    
-         </span>
    
- 
    
-     </div>
    
- 
    
- </ui:composition>
    
 
 
这里依然是使用<ui:insert />作为内容页面的插入块。这里有两块<ui:insert />第一块是有name属性的,第二块则是没有name属性的。如果没有name属性,表示在插入块中没有放在<ui:defind/》里的东西都放在没有name的插入块中。。。比如
    -             <s:decorate id="nameDecoration" template="layout/edit.xhtml">
    
-                 <ui:define name="label">Name</ui:define>
    
-                 <h:inputText id="name" required="true"
    
-                              value="#{bookHome.instance.name}"/>
    
-             </s:decorate>
 
 
这里<ui:defind name="label">这就是定义那个有名字的插入块。而接下来的<h:inputText ... />则是放在了下面没有名字的<ui:insert />中。上面的代码也展示了使用摸板的另一种方式。使用<s:decorate/>使用摸板块,摸板页面的根需要是一个<ui:composition>元素。s:decorate是一个seam元素。必须在seam的管理的页面中使用。
其他:
     jsf中的form是不需要action的。比如<h:form id="login">
    标签的rendered属性表示在什么情况下显示。html标签没有rendered属性,比如div标签没有rendered。
其他的jsf标签我们可以通过学习jsf学习。因为jsf标签,richFaces标签,faceslet标签太多了。这里就不一一介绍了。。。。大家有什么好的资料也麻烦告诉我哦。
 
	posted on 2008-12-15 09:15 
phyeas 阅读(843) 
评论(2)  编辑  收藏  所属分类: 
Seam项目实战