Wicket http wicketframework org The Apache Software License

  • Slides: 32
Download presentation
Wicket拾い読み http: //wicketframework. org/ The Apache Software License 2. 0 suga

Wicket拾い読み http: //wicketframework. org/ The Apache Software License 2. 0 suga

Wicketの細かなこと(3/3) • 実行時依存jar – commons-logging 1. 0. 4, log 4 j 1. 2. 13

Wicketの細かなこと(3/3) • 実行時依存jar – commons-logging 1. 0. 4, log 4 j 1. 2. 13 • compile時依存jar – portlet-api 1. 0, servlet-api 2. 3, junit 3. 8. 1 • XMLPull. Parserなどは内蔵 • Java. Doc、コメントたっぷり – Java. Docを見ればたいてい分かる • Retro. Weaver利用でGenericsコメントあり

開発の簡単な流れ • HTMLを作成 (src/example/Foo. html) – タグにwicket: idを付ける • Pageを作成 – Foo extends Web.

開発の簡単な流れ • HTMLを作成 (src/example/Foo. html) – タグにwicket: idを付ける • Pageを作成 – Foo extends Web. Page • Applicationを作成 – Foo. Application extends Web. Application – get. Home. Page() { return Foo. class; } • web. xmlにWicket. Servlet登録、マッピング – init-param: Foo. Applicationクラス名

入力フォームの構築 • 入力を受けるモデルを作る – POJO (implements Serializable) • Pageでコンポーネントを構築 – add(new Foo. Form("foo. Form",

入力フォームの構築 • 入力を受けるモデルを作る – POJO (implements Serializable) • Pageでコンポーネントを構築 – add(new Foo. Form("foo. Form", model)); – public class Foo. Form extends Form – add(new Text. Field("age", Integer. class) { public IConverter get. Converter() { } });

入力の受け付け (1/4) • 入力を受けるモデルを作成 – Foo. Model implements Serializable • POJO • Pageでコンポーネントを構築 –

入力の受け付け (1/4) • 入力を受けるモデルを作成 – Foo. Model implements Serializable • POJO • Pageでコンポーネントを構築 – Form foo. Form = new Form("foo. Form", new Compound. Property. Model( new Foo. Model() ) );

入力の受け付け (2/4) • foo. Form. add( new Text. Field("url", URL. class) { public IConverter

入力の受け付け (2/4) • foo. Form. add( new Text. Field("url", URL. class) { public IConverter get. Converter() { return new Simple. Converter. . } }. add(new URLValidator()) ); • add(foo. Form); 真骨頂は • サンプル: Form. Input コンポーネント化して 再利用できること

入力の受け付け (3/4) • Compound. Property. Model – POJOをModelとして扱うためのWrapper – componet. idと同名のpropertyを扱う • == テンプレートのwicket:

入力の受け付け (3/4) • Compound. Property. Model – POJOをModelとして扱うためのWrapper – componet. idと同名のpropertyを扱う • == テンプレートのwicket: id – on. Get. Object(Component) – on. Set. Object(Component, Object value) • valueがString, かつcomponent. type != nullなら component. converter. convert(String)で変換 • リフレクションの処理: Property. Resolver

イベント • リンク: a href, onclick – new Link("link. Id") { public void on.

イベント • リンク: a href, onclick – new Link("link. Id") { public void on. Click() { // do } } • Submit – Form#on. Submit() – バリデーションが成功したら呼ばれる

画面遷移 (1/5) • new Page. Link("link. Id", new IPage. Link() { public Page get.

画面遷移 (1/5) • new Page. Link("link. Id", new IPage. Link() { public Page get. Page() { return new Foo(); // Web. Page } public Class get. Page. Identity() { return Foo. class; } } • http: //localhost: 8080/linkomatic? wicket: interfa ce=: 0: action. Link: : ILink. Listener • サンプル: linkomatic

画面遷移 (2/5) • new Bookmarkable. Page. Link( "link. Id", Foo. class). set. Parameter("parametername", "value")

画面遷移 (2/5) • new Bookmarkable. Page. Link( "link. Id", Foo. class). set. Parameter("parametername", "value") – 履歴を持たない、ブックマーク可能なリンク – http: //localhost: 8080/linkomatic? wicket: boo kmarkable. Page=: wicket. examples. linkoma tic. Page 1 – http: //localhost: 8080/niceurl/a/nice/path/to/t he/first/page

画面遷移 (3/5) • 画面遷移の方法 – wicket. settings. IRequest. Cycle. Settings • ONE_PASS_RENDER – いわゆるforward

画面遷移 (3/5) • 画面遷移の方法 – wicket. settings. IRequest. Cycle. Settings • ONE_PASS_RENDER – いわゆるforward • REDIRECT_TO_BUFFER (default) – PRG (バッファに描画しリダイレクト時に返す) – session. Id + query. Stringでbuffering • REDIRECT_TO_RENDER – PRG (リダイレクト時に描画する) – refreshしても大丈夫

画面遷移 (4/5) • 画面遷移の方法 – Wicket. Servlet#do. Get() – web. Application. get. Request. Cycle.

画面遷移 (4/5) • 画面遷移の方法 – Wicket. Servlet#do. Get() – web. Application. get. Request. Cycle. Settings(). get. Render. Strategy() • もしREDIRECT_TO_BUFFERの2回目なら – web. Application. pop. Buffered. Response(session. Id, query) • それ以外なら描画 – wicket. Request. Cycle#request() – #steps() → #step() // 状態を変えつつループ

画面遷移 (5/5) • 入力確認画面 - Form#on. Submit() - Page confirm. Page = get. Page.

画面遷移 (5/5) • 入力確認画面 - Form#on. Submit() - Page confirm. Page = get. Page. Factory(). new. Page( Foo. Confirm. class); confirm. Page. set. Model(get. Model()); cycle. set. Response. Page(confirm. Page); - あるいはget. Page. Factory(). new. Page( Foo. Confirm. class, parameters));

ライフサイクル • Applicationはひとつのみ生成 • Pageはフローの最初で生成 – セッションに格納 – ModelはPage次第 • HTMLファイルの更新監視 – wicket. markup.

ライフサイクル • Applicationはひとつのみ生成 • Pageはフローの最初で生成 – セッションに格納 – ModelはPage次第 • HTMLファイルの更新監視 – wicket. markup. Markup. Cache #load. Markup. And. Watch. For. Changes – 標準は 1秒間隔 (Application#configure())

履歴の管理 • wicket. Page. Map – 通常は無名のみ – page. Idで履歴管理 – セッション内に最大 5 (設定可能)

履歴の管理 • wicket. Page. Map – 通常は無名のみ – page. Idで履歴管理 – セッション内に最大 5 (設定可能) • wicket. Page#get. Version(int) – wicket. version. undo. Undo. Page. Version. Ma nager – 番号 0~ (-1: 最新)

Servlet APIのwrap • wicket. protocol. http. Web. Session – wicket. Session - Thread. Local

Servlet APIのwrap • wicket. protocol. http. Web. Session – wicket. Session - Thread. Local • wicket. protocol. http. Web. Request – wicket. Request • wicket. protocol. http. Web. Response – wicket. Response

Cookieに永続化 • Cookieからセット – Page#set. Form. Component. Values. From. Coo kies() • Visitorパターン :

Cookieに永続化 • Cookieからセット – Page#set. Form. Component. Values. From. Coo kies() • Visitorパターン : Component. IVisitor#component() • Form#load. Persistent. Form. Component. Values() • wicket. markup. html. form. persistence. Cookie. Value. Persister

処理ステップ • wicket. Request. Cycle#step() – PREPARE_REQUEST – RESOLVE_TARGET • wicket. request. compound. Default.

処理ステップ • wicket. Request. Cycle#step() – PREPARE_REQUEST – RESOLVE_TARGET • wicket. request. compound. Default. Request. Target. Resolve. Strategy – PROCESS_EVENTS • 可能ならRESPONDまでsynchronizedで実行 – RESPOND – HANDLE_EXCEPTION

URLのパース (1/2) • wicket. protocol. http. request. Web. Request. Coding. Strategy#decode() – path. Info,

URLのパース (1/2) • wicket. protocol. http. request. Web. Request. Coding. Strategy#decode() – path. Info, "page. Map. Name", "behavior. Id" – interface parameter • <page-map-name>: <path>: <version>: <interface> • 例) wicket: interface=: input. Form: 0: ILink. Listener – bookmarkable parameter • <page-map-name>: <page-class-name> • 例 )wicket: bookmarkable. Page=: wicket. examples. linkomatic. Page 1

URLのパース (2/2) • : <path>: <version>: <interface> – pathにはpage. Id(sequence no)を含む page-map-nameとversion: interfaceを 取り除いたものがpath

URLのパース (2/2) • : <path>: <version>: <interface> – pathにはpage. Id(sequence no)を含む page-map-nameとversion: interfaceを 取り除いたものがpath (component) 例) : 15: input. Form: : ILink. Listener • wicket. request. compound. Default. Request. Target. Resolver. Strategy

例の資料に照らし合わせて (2/4) • Configuration – 全体設定:Applicationクラスにコーディング • wicket. settings. IXxxx. Settings • init() →

例の資料に照らし合わせて (2/4) • Configuration – 全体設定:Applicationクラスにコーディング • wicket. settings. IXxxx. Settings • init() → 環境変数 → init-param → contextparam • Factoryを置きかえることで大抵のことはできる – Converter, Validatorなどはコーディング – 開発モード、運用モード • -Dwicket. configuration=development (default)

例の資料に照らし合わせて (4/4) • User. Interface – 動かすまでは簡単 • wicket. jar, commons-logging. jar, log 4

例の資料に照らし合わせて (4/4) • User. Interface – 動かすまでは簡単 • wicket. jar, commons-logging. jar, log 4 j. jar – Wicket Inspector • /foo? wicket: bookmarkable. Page=: wicket. examp les. debug. Inspector. Page – エラーメッセージがわかりやすいかは不明