トップ ライブラリ/Framework/CMS Seasar2 Teeda 複数選択チェックボックスのサンプル:登録ページから確認ページへ遷移するアプリ

複数選択チェックボックスのサンプル:登録画面から確認画面へ遷移するアプリ-Seasar2(Teeda)

このページでは、Seasar2(Teeda)を使用した複数選択チェックボックスのサンプル(登録画面から確認画面へ遷移するアプリ)について紹介しています。

▲記事トップへ

説明

Doltengプロジェクト作成 を行い、以下のソースを作成します。

ソースコードの内容および配置、動作方法については下記を参照してください。

動作環境

以下の環境を前提に記載。

ソースコード(HTML)

登録ページ(src/main/view/checkbox/entry.html)

チェックボックス(複数選択)を表示するページです。

te:layoutを使用するため、 htmlタグに「xmlns:te="http://www.seasar.org/teeda/extension"」を指定しています。

<html xmlns:te="http://www.seasar.org/teeda/extension">
<head>
<title>サンプル:チェックボックス - 登録</title>
</head>
<body>
<form id="form">
<span id="aaa" te:layout="pageDirection">
<input type="checkbox" name="aaa" value="0"/>
</span>
<input type="submit" id="doConfirm" value="submit"/>
</form>
</body>
</html>

確認ページ(src/main/view/checkbox/confirm.html)

登録ページで選択された項目を表示します。

<html>
<head>
<title>サンプル:チェックボックス - 確認</title>
</head>
<body>
<ul id="bbbItems">
<li><span id="label" ></span></li>
</ul>
</body>
</html>

ソースコード(Java)

共通クラス(src/min/java/checkbox/BasePage.java)

ページ共通部分を扱うクラスです。 登録ページと確認ページ、それぞれで継承して使用します。

ここではページ間で引き継ぐデータを@SubapplicationScope(パッケージ間をスコープにもつ) で定義しています。

aaaItemsはチェックボックスの表示ラベルと値を保持します。 aaaは、選択されたaaaItems(チェックボックス)の要素番号を保持するために用意します。 aaaはTeadaによって自動で設定されます。

package sample.web.checkbox;
import java.util.List;
import java.util.Map;
import org.seasar.teeda.extension.annotation.scope.SubapplicationScope;
public class BasePage {
    @SubapplicationScope
    public Integer[] aaa;
    @SubapplicationScope
    public List<Map> aaaItems;
}

登録ページクラス(src/min/java/checkbox/EntryPage.java)

aaaItems(チェックボックス)の値を設定します。

package sample.web.checkbox;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
public class EntryPage extends BasePage {
    public Class<?> initialize() {
        aaaItems = new ArrayList();
        for (int i = 0; i < 3; i++) {
            Map item = new HashMap();
            item.put("label", "チェックボックス" + i);
            item.put("value", i);
            aaaItems.add(item);
        }
        return null;
    }
    public Class doConfirm() {
        return ConfirmPage.class;
    }
}

確認ページクラス(src/min/java/checkbox/ConfirmPage.java)

登録ページより引き継いだチェックボックスのデータを解析して、 選択されたもの(aaaにリストの要素番号が格納されているもの)だけ、 bbbItemsに詰めます。

bbbとlabelはTeadaがページに表示する際に使用するために用意しています。 labelはMapでlabelという文字列をキーとしているためlabelという名前になっています。

package sample.web.checkbox;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.seasar.teeda.extension.annotation.scope.PageScope;
public class ConfirmPage extends BasePage {
    @PageScope
    public List<Map> bbbItems;
    @PageScope
    public Map bbb;
    @PageScope
    public String label;
    public Class<?> initialize() {
        bbbItems = new ArrayList();
        for (int i = 0; i <  aaa.length; i++) {
            bbbItems.add(aaaItems.get(aaa[i]));
        }
        return null;
    }
}

tomcatの設定(server.xml)

<?xml version='1.0' encoding='utf-8'?>
<Server port="8005" shutdown="SHUTDOWN">

  <!--: 省略-->

  <Service name="Catalina">
    <Connector port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443"
               URIEncoding="UTF-8" />

    <Connector port="8009"
               protocol="AJP/1.3"
               redirectPort="8443"
               URIEncoding="UTF-8" />
    <Engine name="Catalina" defaultHost="localhost">
      <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
             resourceName="UserDatabase"/>
      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="false"
            xmlValidation="false" xmlNamespaceAware="false">
        <Context path="/sample"
                 docBase="<tomcatホームディレクトリ>/webapps/sample"
                 reloadable="true">
        </Context>
      </Host>
    </Engine>
  </Service>
</Server>

アプリの構成

自動生成された<Eclipseプロジェクト配下>src/main/webapp配下を <Tomcatホーム>/webapps/sample配下にコピーする。

□tomcatホームディレクトリ
├─conf
|      server.xml
└─webapps
    └─sample
        │  index.jsp
        ├─view
        │  │  entry.html
        │  │  confirm.html
        │  └─error
        │          error.html
        └─WEB-INF
            │  faces-config.xml
            │  web.xml
            │
            ├─classes
            │  │  app.dicon
            │  │  appMessages.properties
            │  │  appMessages_ja.properties
            │  │  app_aop.dicon
            │  │  convention.dicon
            │  │  creator.dicon
            │  │  customizer.dicon
            │  │  env.txt
            │  │  env_ut.txt
            │  │  jdbc.dicon
            │  │  log4j.properties
            │  │  s2container.dicon
            │  │  teedaCustomize.dicon
            │  │  teedaErrorPage.dicon
            │  ├─checkbox
            │  │      confirm.html
            │  │      entry.html
            │  ├─data
            │  │      demo.sql
            │  ├─error
            │  │      error.html
            │  └─sample
            │      ├─converter
            │      ├─dao
            │      ├─dto
            │      ├─dxo
            │      ├─entity
            │      ├─helper
            │      ├─logic
            │      ├─service
            │      ├─validator
            │      └─web
            │          ├─checkbox
            │          │      BasePage.class
            │          │      ConfirmPage.class
            │          │      EntryPage.class
            │          └─error
            │                  ErrorPage.class
            └─lib
                │  aopalliance-1.0.jar
                │  commons-collections-3.1.jar
                │  commons-el-1.0.jar
                │  commons-fileupload-1.2.jar
                │  commons-io-1.3.2.jar
                │  commons-logging-1.1.jar
                │  geronimo-jta_1.1_spec-1.0.jar
                │  h2-1.0.69.jar
                │  javassist-3.4.ga.jar
                │  jstl-1.1.2.jar
                │  log4j-1.2.13.jar
                │  ognl-2.6.9-patch-20090427.jar
                │  poi-3.0-FINAL.jar
                │  s2-dao-1.0.51.jar
                │  s2-dao-tiger-1.0.51.jar
                │  s2-extension-2.4.43.jar
                │  s2-framework-2.4.43.jar
                │  s2-tiger-2.4.43.jar
                │  teeda-ajax-1.0.13-sp10.jar
                │  teeda-core-1.0.13-sp10.jar
                │  teeda-extension-1.0.13-sp10.jar
                │  teeda-tiger-1.0.13-sp10.jar
                │  xercesImpl-2.6.2.jar
                │  xmlParserAPIs-2.6.2.jar
                └─sources
                        commons-collections-3.1-sources.jar
                        commons-el-1.0-sources.jar
                        commons-fileupload-1.2-sources.jar
                        commons-io-1.3.2-sources.jar
                        commons-logging-1.1-sources.jar
                        log4j-1.2.13-sources.jar
                        s2-dao-1.0.51-sources.jar
                        s2-dao-tiger-1.0.51-sources.jar
                        s2-extension-2.4.43-sources.jar
                        s2-framework-2.4.43-sources.jar
                        s2-tiger-2.4.43-sources.jar
                        teeda-ajax-1.0.13-sp10-sources.jar
                        teeda-core-1.0.13-sp10-sources.jar
                        teeda-extension-1.0.13-sp10-sources.jar
                        teeda-tiger-1.0.13-sp10-sources.jar

動作確認

tomcatを起動し、ブラウザより「http://<tomcatサーバのホスト>:8080/sample/view/checkbox/entry.html」へアクセスし、 チェックボックスを選択し、 submitボタンを押下すると、confirm.htmlに遷移し、 選択した項目が表示されます。

もっと知識を広げるための参考

もっと知識を広げるための参考です。

Seaser2

Seasar2は、JavaのWebアプリケーション開発フレームワークで日本のオープンソースプロジェクトの1つです。 DI(Dependecy Injection:依存性の注入)や命名規則による簡単かされたプログラミングなどの特徴があります。 ただ2016年9月26日をもってサポート終了となっています。

詳細

戻る

スポンサーリンク

サイト内のページ

言語
C・C++ /HTML /Java /JavaScript /PHP /シェルスクリプト

開発環境
Ant /Burp /Eclipse /Fiddler /gcc /gdb /Git /g++ /JDK /JMeter /JUnit /Teraterm /ZAP

技術・仕様
Ajax /CORBA /Jakarta EE(旧称J2EE、Java EE) /JNI

ライブラリ/Framework/CMS
bootstrap /jQuery /FuelPHP /Lucene /MyBatis /Seasar2 /Spring /Struts /WordPress

Web API
Google Maps

ITインフラOSとミドルウェア
Linux /Windows /シェル
ActiveMQ /Tomcat /MariaDB /MySQL /Nagios /Redis /Solr

ITインフラサーバー
公開Webサーバー

ITインフラネットワーク
プログラミング /構築

ITインフラセキュリティ
公開サーバーのセキュリティ

PC製品
ZOTAC

SI
ホームページの作り方

その他
IT用語 /ITスキル体系

スポンサーリンク

関連サイト内検索ツール

zealseedsおよび関連サイト内のページが検索できます。

IPアドレス確認ツール

あなたのグローバルIPアドレスは以下です。

44.213.75.78

HTMLの表示色確認ツール

パスワード生成ツール

文字数のプルダウンを選択して、取得ボタンを押すと「a~z、A~Z、0~9」の文字を ランダムに組み合わせた文字列が表示されます。

ここに生成されます。

スポンサーリンク