RichFaces4 ShowCaseのDropDownMenuを実行します。
【手順】
1.「RichFaces4プロジェクトの作成方法」の手順で、「RichFaces4Sample015-DropDownMenu」といプロジェクトを作成。
※プロジェクトの設定は以下の通り。
2.「WebContent/WEB-INF/web.xml」を以下の様に入力。
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>RichFaces4Sample015-DropDownMenu</display-name> <welcome-file-list> <welcome-file>faces/index.xhtml</welcome-file> </welcome-file-list> <servlet> <servlet-name>Faces Servlet</servlet-name> <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Faces Servlet</servlet-name> <url-pattern>/faces/*</url-pattern> </servlet-mapping> </web-app>
3.「Ctrl+Shift+F」を押し、ソースコードをフォーマッティング、「Ctrl+S」でファイルを保存。
4.「Javaパッケージの作成方法」の手順で、「com.example.richfaces4sample015」というパッケージを作成。
5.「Javaクラスファイルの作成方法」の手順で、「DropDownMenuBean.java」というクラスファイルを作成。
6.「DropDownMenuBean.java」を以下の様に入力。
package com.example.richfaces4sample015; import javax.faces.bean.ManagedBean; import javax.faces.bean.RequestScoped; @ManagedBean @RequestScoped public class DropDownMenuBean { private String selectedCommand; public String getSelectedCommand() { return selectedCommand; } public void setSelectedCommand(String selectedCommand) { this.selectedCommand = selectedCommand; } public void doNew() { selectedCommand = "選択されたコマンド:新規"; } public void doExit() { selectedCommand = "選択されたコマンド:終了"; } public void doSearch() { selectedCommand = "選択されたコマンド:検索実行"; } }
7.「Ctrl+Shift+F」を押し、ソースコードをフォーマッティング、「Ctrl+S」でファイルを保存。
8.「任意のファイルの作成方法」の手順で、「WebContent/」ディレクトリに「index.xhtml」というファイルを作成。
9.「index.xhtml」を以下の様に入力。
<html xmlns="http://www.w3c.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:a4j="http://richfaces.org/a4j" xmlns:rich="http://richfaces.org/rich"> <h:head> </h:head> <h:body> <h:form> <rich:toolbar> <rich:dropDownMenu> <f:facet name="label"> <h:panelGroup> <h:outputText value="ファイル" /> </h:panelGroup> </f:facet> <rich:menuItem submitMode="ajax" label="新規" action="#{dropDownMenuBean.doNew}" reRender="out"> </rich:menuItem> <rich:menuSeparator /> <rich:menuItem submitMode="ajax" label="終了" action="#{dropDownMenuBean.doExit}" reRender="out" /> </rich:dropDownMenu> <rich:dropDownMenu> <f:facet name="label"> <h:outputText value="リンク" /> </f:facet> <rich:menuItem> <h:outputLink value="http://labs.jboss.com/jbossrichfaces/"> <h:outputText value="RichFaces Home Page" /> </h:outputLink> </rich:menuItem> <rich:menuItem> <h:outputLink value="http://www.google.com"> <h:outputText value="Google" /> </h:outputLink> </rich:menuItem> </rich:dropDownMenu> <rich:toolbarGroup location="right"> <rich:dropDownMenu direction="bottomLeft" jointPoint="bottomRight"> <f:facet name="label"> <h:panelGroup> <h:outputText value="検索" /> </h:panelGroup> </f:facet> <rich:menuItem submitMode="ajax" label="検索実行" action="#{dropDownMenuBean.doSearch}" reRender="out"> </rich:menuItem> </rich:dropDownMenu> </rich:toolbarGroup> </rich:toolbar> <h:outputText id="out" value="#{dropDownMenuBean.selectedCommand}" /> </h:form> </h:body> </html>
10.「Ctrl+Shift+F」を押し、ソースコードをフォーマッティング、「Ctrl+S」でファイルを保存。
11.「動的Webアプリケーションをサーバーに配置する方法」の手順で、作成したプロジェクトをサーバーに配置します。
12.「サーバーをデバッグモードで起動する方法」の手順で、サーバーを起動します。
13.ブラウザで以下のURLにアクセスします。
http://localhost:8080/RichFaces4Sample015-DropDownMenu/faces/index.xhtml
14.以下の様に表示されれば成功です。
以上です。
0 件のコメント:
コメントを投稿
注: コメントを投稿できるのは、このブログのメンバーだけです。