+ All Categories
Home > Technology > Apache Tapestry

Apache Tapestry

Date post: 28-May-2015
Category:
Upload: akio-katayama
View: 1,614 times
Download: 0 times
Share this document with a friend
Description:
知っ得納得Webフレームワーク勉強会のスライド
44
Apache Tapestry -- Open-source framework for creating dynamic, robust, highly scalable web applications --
Transcript
Page 1: Apache Tapestry

Apache Tapestry-- Open-source framework for creating dynamic,

robust, highly scalable web applications --

Page 2: Apache Tapestry

自己紹介

名前

片山暁雄

IDid:c9katayama

[email protected]所属

株式会社キャピタルアセットプランニングhttp://www.cap-net.co.jp

チームT2Frameworkhttp://code.google.com/p/t-2/

Page 3: Apache Tapestry

Agenda

Tapestryとは

基本的な仕組み

PageとtmlComponent・ MixinIoC ・Moduleその他機能

利点欠点

まとめ

Page 4: Apache Tapestry

Tapestry

Tapestryとは

Page 5: Apache Tapestry

Tapestryとは

Apach傘下で開発中のWebフレームワーク

トッププロジェクト

Servlet・JSPは使用しない

イベントドリブン

HTMLテンプレート・コンポーネント

JSFに似てる(?)

IoCコンテナ内臓

Page 6: Apache Tapestry

Tapestryとは

2001年ごろに開発開始

現在バージョン5後方互換性なし

JDK5以上

Apache2.0 License

Page 7: Apache Tapestry

Tapestry

基本的な仕組み

Page 8: Apache Tapestry

Tapestry USER

基本的な仕組み

TapestryFilter

Page

Component

.tml

Browser

Registry

Module

HttpServletRequestHandler

Filter

Filter

Filter

Filter

Service

Module

URL

Page 9: Apache Tapestry

パッケージ構成

USERクラスの登録

ルートパッケージをweb.xmlで指定

他の設定ファイルなし

<context-param>param-name>tapestry.app-package</param-name>

<param-value>org.apache.tapestry5.tutorial</param-value></context-param>

Page 10: Apache Tapestry

パッケージ構成

ルートパッケージ以下pagesservicescomponentsmixinsbase

特別なフォルダこのフォルダからのパッケージ階層も重要

Page 11: Apache Tapestry

Tapestry

Pageとtml

Page 12: Apache Tapestry

Pageとtml

Pageクラス

画面の情報を保持したり、画面からのアクションを受け取ったりするクラス

URLと1対1でひも付け

tml(TapestryMarkupLanguage)ファイル

HTMLテンプレートファイル

Pageと1対1でひも付け

URL = Page = tml

Page 13: Apache Tapestry

Pageとtml

public class GameStart{ @Propertyprivate int guess;

@Persistprivate int target;@InjectPageprivate GameOver gameOver;void initialized(int target){

this.target = target;}@OnEvent(component=“ansLink”)Object handleAnsLink(int guess) {

return target==guss ? gameOver. : null;}

}

Pageクラス

Page 14: Apache Tapestry

Pageとtml

<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd"><head>

<title>Guess A Number</title></head><body>

<p>Make a guess between one and ten:</p><p>${message}</p><t:loop source="1..10" value="guess" xml:space="preserve">

<t:actionlink t:id=“ansLink" context="guess">${guess}</t:actionlink></t:loop>

</body></html>

tml

Page 15: Apache Tapestry

Pageとtml

Page(hoge/Foo.java)

@PropertyString message

@OnEvent(component=“ansLink”)

Object handleAnsLiks(){}

.tml(hoge/Foo.tml)

${message}

<t:actionlinkt:id=“ansLink“>

レンダリング時にPageから値を

取得

画面アクション時にPageのメソッドを

コールバック

Page 16: Apache Tapestry

Pageとtml

Pageクラス

POJO(クラスアノテーションもなし)

${app-package}.pagesパッケージに格納

自動登録

URLと1対1のマッピング

例えば${rootpkg}/pages/hoge/Foo.javaの場合、

http://host/context_root/hoge/fooとマッピングされる

Page 17: Apache Tapestry

Pageとtml

フィールドアノテーション@Property

アクセサを自動生成

宣言しないで自分でアクセサをつけてもOK

@Persist他の画面に行っても持ち越す値に付与

セッションに値が入る

@Retainリクエスト間で値を保持したい場合に付与

Page 18: Apache Tapestry

Pageとtml

@InjectコンテナからDIしてほしい場合に付与

@InjectService名前指定でサービスをDIしてほしい場合に付与

@InjectPage次の画面のインスタンスが欲しい場合に宣言

イベントハンドラーから返すと、その画面に遷移

Page 19: Apache Tapestry

Pageとtml

メソッドアノテーション@OnEvent

「value=EventConstantsの定数」で、各イベント発

生時のハンドル可能

component=コンポーネントidで、指定のコンポーネ

ントのアクションをハンドル可能

ACTION ACTIVATE PASSIVATE PREPARE_FOR_RENDER PREPARE_FOR_SUBMIT PREPARE SUBMIT VALIDATE_FORM SUCCESS FAILURE SELECTED PARSE_CLIENT TO_CLIENT VALIDATE REMOVE_ROW ADD_ROW

Page 20: Apache Tapestry

Pageとtml

@OnEventアノテーションは、

onアクション

onアクションFromコンポーネントid

でも代用可能

@OnEvent(value=EventConstanst.ACTION,component=“ansLink”)

public Object hoge(){}

public Object onActionFromAnsLink (){}

Page 21: Apache Tapestry

Pageとtml

tmlXHTML形式

ドキュメントルート以下、もしくは

${pkgbase}.pagesパッケージに格納

独自タグ、もしくはHTMLの要素で、コンポーネントを記述

<a t:type="pagelink" t:page="address/create">

<t:pagelink page=“address/create”>

いずれも同じ

Page 22: Apache Tapestry

Pageとtml

タグ部分はレンダリング時にHTMLに置き換わる

${value}を使って、Pageクラスから値を取得

リンク、フォームなどのクリックで発生する

リクエストを、Pageに通知

Page 23: Apache Tapestry

Tapestry

Component・Mixin

Page 24: Apache Tapestry

コンポーネント

ComponentJavaクラス、tmlファイル、リソース

(js,image,CSS)をひとまとめにしたもの。

${tapestry.app-package}.componentsパッケー

ジに格納

Page 25: Apache Tapestry

コンポーネント

作り方Javaクラスを作成

必要ならtmlを作成

画像・JavaScript・CSSなどが必要な場合はJavaクラスに宣言

実際のコード

Page 26: Apache Tapestry

コンポーネント

使い方tml内でコンポーネントを宣言

<t:hoge.foo.Componentid=“mycmp” bar=“XXX” />

Page 27: Apache Tapestry

コンポーネント

コンポーネントツリーPageをルートとしたツリー

ツリーに従いレンダリングやイベント伝播を行う

Page

Pagelayout

formpagelink

Page 28: Apache Tapestry

コンポーネント

組み込みComponentForm,Label,TextFieldPageLink,ActionLink,LinkSubmitIf,UnlessGridBeanDisplay,BeanEditor

Page 29: Apache Tapestry

コンポーネント

Mixin既存のComponentに対して、機能を追加する

ためのもの

Componentの各処理に割り込む

作り方はComponentと一緒

ただしtmlは使用不可

Page 30: Apache Tapestry

コンポーネント

使い方コンポーネント宣言に使用するmixinを宣言

<t:TextFieldt:mixins=“autocomplete" id=“mytxt” />

Page 31: Apache Tapestry

コンポーネント

組み込みMixinAutocompleteRenderDisabledRenderInformals

Page 32: Apache Tapestry

Tapestry

IoC・ Module

Page 33: Apache Tapestry

ServiceBinder

IoCTapestry組み込みのIoCコンテナ

tapestry5-ioc.jarで提供

本体はtapestry5-core.jar

IoC・Module

Registry Module

Service1

Service2Service1

Service2

bind

Page 34: Apache Tapestry

IoC・Module

RegistryServiceの集合体

インターフェースとその実装クラス、及び設定(contribute、decorate)の情報を保持

コアコンポーネント・ユーザーコンポーネントすべてをこのRegistryから取り出す

@Inject,@InjectServiceのついたフィールドに

インジェクション

Page 35: Apache Tapestry

IoC・Module

ModuleServiceと設定をRegistryに登録する役割

${app.package}/services/アプリ名Module.classがTapestryFilter初期化時に自動的に呼ばれる

すべてstaticメソッド

bind()で、サービスをbindcontributeサービス名()で、そのサービスの設定

decorateサービス名()で、サービスデコレーターの設

Page 36: Apache Tapestry

Tapestry

その他機能

Page 37: Apache Tapestry

その他機能

オートリロード機能pages、components、mixins、baseパッケージ

内のクラスやリソースをリロード

Ajax対応

zone機能(指定の<div>の中身だけを書き換え)

詳細なエラーページ

Page 38: Apache Tapestry

Tapestry

利点・欠点

Page 39: Apache Tapestry

利点

HTMLテンプレートが利用できる

URLとクラス・テンプレートの位置関係

が明確

コンポーネント作成が容易・再利用が可能

IoCコンテナ内臓 カスタマイズが柔軟

オートリロード機能でAPサーバ再起動な

しの開発が可能

Page 40: Apache Tapestry

欠点

学習コストが高い機能が多いので、すべて知るに時間がかかる

ソースが追いくい匿名クラスやエンハンスされたクラスが多い

ライフサイクルがわかりにくい

Seasar2,Guiceは使用不可今出ているのはHiveMindとSpringのアダプタだけ

ORマッパー・トランザクションとの連携Hibernate連携以外は?

Page 41: Apache Tapestry

Tapestry

まとめ

Page 42: Apache Tapestry

まとめ

Tapestryは、イベントドリブン・コンポーネント指向・HTMLテンプレート

IoCコンテナ・リロード機能つき

結構すごいが学習コストが高め

とりあえず 抱かれてみよう Tapestry

Page 43: Apache Tapestry

まとめ

参考文献Apache Tapestry

http://tapestry.apache.org/

有志の日本語訳http://kuramo.ch/tapestry5/ja/

Page 44: Apache Tapestry

まとめ

ご静聴ありがとうございました


Recommended