読者です 読者をやめる 読者になる 読者になる

JSFのサンプル

index.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://xmlns.jcp.org/jsf/html">
    <h:head>
        <title>Sample02</title>
    </h:head>
    <h:body>
        <h2>名簿データの作成</h2>
        <h:form>
            番号:<h:inputText value="#{meiboBean.number}" /><br/>
            氏名:<h:inputText value="#{meiboBean.name}" /><br/>
            <h:commandButton value="送信"  action="#{meiboBean.next()}"/>
        </h:form>
    </h:body>
</html>

Output.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://xmlns.jcp.org/jsf/html">
    <h:head>
        <title>Sample02</title>
    </h:head>
    <h:body>
        <h2>名簿データの確認</h2>
        <h:form>
            番号:<h:outputText value="#{meiboBean.number}"/><br/>
            氏名:<h:outputText value="#{meiboBean.name}"/><br/>
            <h:link outcome="index">[戻る]</h:link>
        </h:form>
    </h:body>
</html>

MeiboBean.java

package beans;

import javax.enterprise.context.RequestScoped;
import javax.inject.Named;

@Named
@RequestScoped
public class MeiboBean {

    private Integer number;
    private String name;

    public String next() {
        System.out.println("★number=" + this.number + "/ name=" + this.name);
        return "output.xhtml"; // 次に表示するウェブページ
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getNumber() {
        return number;
    }

    public void setNumber(Integer number) {
        this.number = number;
    }
}