<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>/WEB-INF/faces-config.xml</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
</web-app>
<managed-bean-name>該bean的別名</managed-bean-name>
<managed-bean-class>
該bean所在位置(包名+類名)
</managed-bean-class>
<managed-bean-scope>該bean的存在範圍(session,request,application,none四種)</managed-bean-scope>
</managed-bean>
<from-view-id>/輸入的頁面名</from-view-id>
<navigation-case>
<from-outcome>代表跳轉到哪裏的字符串(這裏可以隨便定義)</from-outcome>
<to-view-id>/跳轉的頁面名</to-view-id>
</navigation-case>
</navigation-rule>
<h:outputText value="#{backing bean名.字段名}"></h:outputText> //要輸出到頁面的值
<h:form> //form
<h:inputText value="#{backing bean名.字段名}"></h:inputText><br/> //要輸入的字段
<h:commandButton action="#{backing bean名.業務方法}" value="按鈕文字"></h:commandButton>
</h:form>
</f:view>
if(驗證不通過條件){
FacesMessage fm = new FacesMessage(FacesMessage.SEVERITY_ERROR, "數值不通過原因", "顯示在頁面上的信息");
throw new ValidatorException(fm);
}
}
<validator-id>驗證類的別名</validator-id>
<validator-class>驗證類的包名+類名</validator-class>
</validator>
<message-bundle>國際化文件的前綴名(不含_zh_CN之類)</message-bundle>
<locale-config>
<default-locale>en</default-locale>(默認國際化語言,只能有1個)
<supported-locale>zh_CN</supported-locale>(支持的國際化語言,可以多個)
</locale-config>
</application>
<f:loadBundle basename="國際化文件前綴名" var="國際化文件別名" />
<h:outputLabel value="#{別名['鍵名']}"></h:outputLabel>
</f:view>
<f:loadBundle basename="message" var="m" />
<h:outputLabel value="#{m['label.showtext']}"></h:outputLabel>
<h:form>
<h:selectOneMenu value="#{cl.language}"> //使用下拉框取得用戶選擇值
<f:selectItem itemValue="en" itemLabel="#{m['select.en']}" />
<f:selectItem itemValue="zh_CN" itemLabel="#{m['select.zh']}" />
</h:selectOneMenu>
<h:commandButton type="submit" action="#{cl.change}" value="go"></h:commandButton> //只是跳轉的方法
</h:form>
</f:view>
標籤 | 說明 |
view | 創建頂層視圖 |
subview | 創建視圖的子視圖 |
facet | 向組件添加 facet |
param | 向組件添加參數 |
attribute | 向組件添加屬性 |
actionListener | 在父組件上註冊操作監聽器 |
valueChangeListener | 向父組件註冊值變更監聽器 |
converter | 註冊任意轉換器 |
convertDateTime | 註冊日期時間轉換器 |
convertNumber | 註冊數量轉換器 |
validateLength | 驗證組件值的長度 |
validateDoubleRange | 驗證組件值的雙精度範圍 |
validateLongRange | 驗證組件值的長整型範圍 |
validator | 向組件添加驗證器 |
loadBundle | 加載資源包 |
verbatim | 向頁面中添加標籤 |
selectItem | 指定 UISelectOne 或 UISelectMany 組件的一個項目 |
selectItems | 指定 UISelectOne 或 UISelectMany 組件的多個項目 |
組件 | 標籤 | 說明 |
UIForm | form | 表示 HTML表單元素 |
UIInput | InputText | 單行文本輸入控件 |
inputTextarea | 多行文本輸入控件 | |
InputSecret | 密碼輸入控件 | |
inputHidden | 隱藏字段 | |
UIOutput | outputLabel | 顯示文本 |
outputLink | 鏈接到另一頁面或某頁面上的特定位置 | |
outputFormat | 顯示格式化的信息 | |
outputText | 當行文本輸入 | |
UICommand | commandButton | 表示一個按鈕 |
commandLink | 表示一個鏈接 | |
UISelectOne | SelectOneListbox | 單選列表框 |
selectOneMenu | 單選菜單 | |
selectOneRadio | 單選按鈕集 | |
UISelectBoolean | selectBooleanCheckbox | 單個複選框 |
UISelectMany | selectManyListbox | 複選框集 |
selectManyCheckbox | 多行選擇列表框 | |
selectManyMenu | 多選菜單 | |
UIPanel | panelGrid | 表示一 個 HTML 表格 |
panelGroup | 組合一系列組件 | |
UIMessage | message | 顯示一個組件的最近使用的消息 |
messages | 顯示所有消息 | |
UIGraphic |
graphicImage | 顯示一個圖像 |
UIData | dataTable | 功能豐富的表格控件 |
UIColumn | column | 表示表格中的列 |
表單 | h:form | 產生 HTML form 元素 |
<h:outputText value="Begin local testing" /> //JSF的輸出標籤
</c:if>
<c:if test="${'false' == TestData.isDebug}">
<h:outputText value="End local testing" />
</c:if>