首先看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標簽太多了。這里就不一一介紹了。。。。大家有什么好的資料也麻煩告訴我哦。