JSF1.2のinputTextのconverterMessageを実行します。
【手順】
1.「JSF1.2プロジェクトの作成方法」の手順で、「JSF12Sample005-ConverterMessage」といプロジェクトを作成。
※プロジェクトの設定は以下の通り。
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>JSF12Sample005-ConverterMessage</display-name>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<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.jsf12sample005」というパッケージを作成。
5.「Javaクラスファイルの作成方法」の手順で、「ValidateLongRangeBean.java」というクラスファイルを作成。
6.「ValidateLongRangeBean.java」を以下の様に入力。
package com.example.jsf12sample005;
import java.io.Serializable;
public class ValidateLongRangeBean implements Serializable {
private Integer number;
public Integer getNumber() {
return number;
}
public void setNumber(Integer number) {
this.number = number;
}
}
7.「Ctrl+Shift+F」を押し、ソースコードをフォーマッティング、「Ctrl+S」でファイルを保存。
8.「WebContent/WEB-INF/faces-config.xml」を以下の様に入力。
<?xml version="1.0" encoding="UTF-8"?>
<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_1_2.xsd"
version="1.2">
<managed-bean>
<managed-bean-name>validateLongRangeBean</managed-bean-name>
<managed-bean-class>com.example.jsf12sample005.ValidateLongRangeBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<application>
<view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
</application>
</faces-config>9.「Ctrl+Shift+F」を押し、ソースコードをフォーマッティング、「Ctrl+S」でファイルを保存。
10.「任意のファイルの作成方法」の手順で、「WebContent/」ディレクトリに「index.xhtml」というファイルを作成。
11.「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">
<head>
</head>
<body>
<f:view>
<h:form id="helloForm1">
<h:inputText id="number" value="#{validateLongRangeBean.number}"
converterMessage="入力値が不正です。">
<f:validateLongRange minimum="1" maximum="10" />
</h:inputText>
<h:commandButton value="送信" />
<h:outputText value="#{validateLongRangeBean.number}" />
<br />
<h:message showSummary="true" showDetail="false" for="number" />
</h:form>
</f:view>
</body>
</html>
12.「Ctrl+Shift+F」を押し、ソースコードをフォーマッティング、「Ctrl+S」でファイルを保存。
13.「動的Webアプリケーションをサーバーに配置する方法」の手順で、作成したプロジェクトをサーバーに配置します。
14.「サーバーをデバッグモードで起動する方法」の手順で、サーバーを起動します。
15.ブラウザで以下のURLにアクセスします。
http://localhost:8080/JSF12Sample005-ConverterMessage/faces/index.xhtml
16.以下の様に表示されれば成功です。
17.以下の様なHTMLが出力されました。
<html xmlns="http://www.w3c.org/1999/xhtml"> <head> </head> <body> <form id="helloForm1" name="helloForm1" method="post" action="/JSF12Sample005-ConverterMessage/faces/index.xhtml;jsessionid=F8F873E6E67603B490B313AF571CDE87" enctype="application/x-www-form-urlencoded"> <input type="hidden" name="helloForm1" value="helloForm1" /> <input id="helloForm1:number" type="text" name="helloForm1:number" /> <input type="submit" name="helloForm1:j_id1" value="送信" /> <br /> <input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="-653846940980647007:-1494293985438975095" autocomplete="off" /> </form> </body> </html>
<html xmlns="http://www.w3c.org/1999/xhtml"> <head> </head> <body> <form id="helloForm1" name="helloForm1" method="post" action="/JSF12Sample005-ConverterMessage/faces/index.xhtml" enctype="application/x-www-form-urlencoded"> <input type="hidden" name="helloForm1" value="helloForm1" /> <input id="helloForm1:number" type="text" name="helloForm1:number" value="aaa" /> <input type="submit" name="helloForm1:j_id1" value="送信" /> <br /> 入力値が不正です。 <input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="-653846940980647007:7340107083302877477" autocomplete="off" /> </form> </body> </html>
<html xmlns="http://www.w3c.org/1999/xhtml"> <head> </head> <body> <form id="helloForm1" name="helloForm1" method="post" action="/JSF12Sample005-ConverterMessage/faces/index.xhtml" enctype="application/x-www-form-urlencoded"> <input type="hidden" name="helloForm1" value="helloForm1" /> <input id="helloForm1:number" type="text" name="helloForm1:number" value="11" /> <input type="submit" name="helloForm1:j_id1" value="送信" /> <br /> helloForm1:number: Validation Error: Specified attribute is not between the expected values of 1 and 10. <input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="-653846940980647007:3481335338243964436" autocomplete="off" /> </form> </body> </html>
以上です。
converterMessage-01.jpg)
converterMessage-02.jpg)
0 件のコメント:
コメントを投稿
注: コメントを投稿できるのは、このブログのメンバーだけです。