JSF 2パスワードの例
JSFでは、
<h:inputSecret/>
タグを使用して、
type = “password”
、パスワードフィールドのHTML入力をレンダリングできます。例えば、
JSFタグ…
<h:inputSecret/>
このHTMLコードをレンダリングする…
<input type="password" name="j__idt6:j__idt7" />
P.S name属性の値は、JSF.
によってランダムに生成されます。
JSFパスワードの例
1.マネージドBean
単純なマネージドBeanで、「パスワード」プロパティを持ちます。
package com.mkyong.form; import javax.faces.bean.ManagedBean; import javax.faces.bean.SessionScoped; import java.io.Serializable; @ManagedBean @SessionScoped public class UserBean implements Serializable { private String password; public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } }
2.ページを見る
デモンストレーションのための2ページ。
-
demo.xhtml ** – “h:inputSecret”を介してパスワードフィールドをレンダリングし、 “h:commandButton”を介してボタンをクリックすると、パスワード値はsetPassword()メソッドを介して “userBean.password” 「user.xhtml」に転送します。
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html"> <h:body> <h1>JSF 2 password example</h1> <h:form> Password : <h:inputSecret value="#{userBean.password}"/> <h:commandButton value="Submit" action="user"/> </h:form> </h:body> </html>
-
user.xhtml ** – “h:outputText”を介して提出されたパスワード値を表示する
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html"> <h:body> <h1>JSF 2 password example</h1> Password : <h:outputText value="#{userBean.password}"/> </h:body> </html>
デモ
URL:http://localhost:8080/JavaServerFaces/
「demo.xhtml」ページを表示する
ボタンをクリックすると、 “user.xhtml”ページと提示されたパスワード値が表示されます。
ソースコードをダウンロードする
ダウンロード – リンク://wp-content/uploads/2010/09/JSF-2-Password-Example.zip[JSF-2-Password-Example.zip](9KB)
リファレンス
<h:inputSecret/> JavaDoc]