Apache MyFaces とは,JSF の機能を実装したプログラムの一種です.Apache MyFaces に特有の 拡張機能もあります. JSF は便利ですし,Apache MyFaces の拡張機能も魅力的です.
このページでは, Apache MyFaces が持つ拡張機能のうち テーブルについて, プログラムの見本や,説明する.
「JavaServer Faces サンプルプログラム」の Web ページの記述に従って,下記の作業を終えていること.
http://www.irian.at/myfacesexamples/home.jsf (現存しない) に記載されていたテーブル(Data Table)(Sortable) を使うプログラムの見本と操作手順を説明する.
「ウインドウ」→「ビューの表示」→「プロジェクト・エクスプローラ」 と操作する.
Java パッケージの作成,クラスの作成などの作業は,プロジェクト・エクスプローラで行う.
プロジェクト・エクスプローラに,プロジェクト一覧が表示されているはずです. Java パッケージを新規作成したいプロジェクト名 MYFACES を右クリックして, 「新規」→「パッケージ」と操作する.
「Java パッケージ (Java package)」の名前として,Java パッケージ名 org.apache.myfaces.examples.listexampleを記入する.
その後,「終了」をクリック.
プロジェクト・エクスプローラにおいて, Java パッケージ org.apache.myfaces.examples.listexample が増えていることを確認する.
プロジェクト MYFACES のパッケージ hoge.hoge.com にインポート
<%@ page session="false" contentType="text/html;charset=utf-8"%> <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%> <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%> <%@ taglib uri="https://myfaces.apache.org/tomahawk" prefix="t"%> <html> <!-- /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ //--> <body> <f:view> <h:form> <t:dataTable styleClass="standardTable" headerClass="standardTable_SortHeader" footerClass="standardTable_Footer" cellpadding="2" cellspacing="2" width="100%" border="1" var="car" value="#{list.cars}" sortColumn="#{list.sort}" sortAscending="#{list.ascending}" preserveDataModel="false"> <f:facet name="header"> <h:outputText value="(header table)" /> </f:facet> <f:facet name="footer"> <h:outputText value="(footer table)" /> </f:facet> <h:column> <f:facet name="header"> <t:commandSortHeader columnName="type" arrow="true" id="type"> <h:outputText value="type" id="t1" /> </t:commandSortHeader> </f:facet> <h:outputText value="#{car.type}" /> </h:column> <h:column> <f:facet name="header"> <t:commandSortHeader columnName="color" arrow="true" id="color"> <h:outputText value="color" id="c1" /> </t:commandSortHeader> </f:facet> <h:outputText value="#{car.color}" /> </h:column> </t:dataTable> </h:form> </f:view> </body> </html>
Tomcat 6.0 用の設定例です.
<?xml version="1.0"?> <faces-config xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd" version="2.0"> <managed-bean> <managed-bean-name>list</managed-bean-name> <managed-bean-class>org.apache.myfaces.examples.listexample.SimpleSortableCarList</managed-bean-class> <managed-bean-scope>session</managed-bean-scope> </managed-bean> </faces-config>