cubby 2006-08-23
DESCRIPTION
Cubbyコンセプトの資料です。現在の仕様(Cubby-1.0)とは仕様がかなり異なります。TRANSCRIPT
![Page 1: Cubby 2006-08-23](https://reader036.vdocuments.pub/reader036/viewer/2022082700/549a36dbac79590e2e8b5aa5/html5/thumbnails/1.jpg)
Cubby100% Pure JSPWeb Application Framework
2006/8/19@Nulab Jaian RecitalToshitaka Agata([email protected])
![Page 2: Cubby 2006-08-23](https://reader036.vdocuments.pub/reader036/viewer/2022082700/549a36dbac79590e2e8b5aa5/html5/thumbnails/2.jpg)
2
Cubbyって何?
100% Pure JSP Web Application Framework
Zero Configuration
ベリーシンプル&スモール
- クラス数約 50個
RESTっぽい URIをサポート
直感的な名前のタグライブラリ
Cubby = 整理棚
![Page 3: Cubby 2006-08-23](https://reader036.vdocuments.pub/reader036/viewer/2022082700/549a36dbac79590e2e8b5aa5/html5/thumbnails/3.jpg)
3
なぜに JSP?
最近嫌われ者のJSP・・・
- スクリプトレットだし、
- エラーがわかりにくいし、
- Pure HTMLテンプレートじゃないし、
- 流行りではないし、
- etc...
![Page 4: Cubby 2006-08-23](https://reader036.vdocuments.pub/reader036/viewer/2022082700/549a36dbac79590e2e8b5aa5/html5/thumbnails/4.jpg)
4
なぜに JSP?
学習容易性
- 新しい知識はいりません。
最近の JSP2.0はいい感じです。- EL式 (Expression Language)
- JSTL(JSP Standard Tag Library)
- Functions
- タグファイル
フラグメント
Dynamic Attributes
- エラー出力の改善
![Page 5: Cubby 2006-08-23](https://reader036.vdocuments.pub/reader036/viewer/2022082700/549a36dbac79590e2e8b5aa5/html5/thumbnails/5.jpg)
5
Cubbyの概要Struts,WebWork,Ruby on Railsの良いところを参考に。
ブラウザDispatcher
Filter
Controller
+ FormObject
+ActionMethod1+ActionMethod2
2.Binding3.Validation4.Action Execute
JSP View
5.Forward
1.Request
7.Response
Custom Tag(Tag File)
&Functions
6.Rendering
Strutsとだいたい同じ範囲をカバーします。やり方はだいぶ異なります
ActionFilter Stack
![Page 6: Cubby 2006-08-23](https://reader036.vdocuments.pub/reader036/viewer/2022082700/549a36dbac79590e2e8b5aa5/html5/thumbnails/6.jpg)
6
View( JSP) 基本は HTMLのタグ。
Cubbyに必要な属性を追記します。
<%@ taglib tagdir="/WEB-INF/cubby/tags" prefix="t" %><t:input name=”userId”/><t:select name=”typeId” items=”${todoTypes}” valueProperty=”id” labelProperty=”name”> <option value=”1”>仕事 </option> <option value=”2”>個人 </option> <option value=”3”>その他 </option></t:select>
Pure JSP
<input name=”userId” value=””/><select name=”typeId”> <option value=”1”>仕事 </option> <option value=”2”>個人 </option> <option value=”3”>その他 </option></select>
Pure HTML
![Page 7: Cubby 2006-08-23](https://reader036.vdocuments.pub/reader036/viewer/2022082700/549a36dbac79590e2e8b5aa5/html5/thumbnails/7.jpg)
7
View( JSP)
全てのカスタムタグはタグファイルでできています! (WEB-INF/tags/*.tag)
Dynamic Attributesで、定義していない属性も出力可能です!
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %><%@ taglib uri="http://www.nulabco.jp/cubby" prefix="f" %><%@ tag dynamic-attributes="dyn" %><%@ attribute name="type" type="java.lang.String" rtexprvalue="true" required="true" %><%@ attribute name="checkedValue" type="java.lang.Object" rtexprvalue="true" required="false" %><input type="${type}" ${f:toAttr(dyn)} ${f:checked(dyn['value'],checkedValue)}/>
input.tag
![Page 8: Cubby 2006-08-23](https://reader036.vdocuments.pub/reader036/viewer/2022082700/549a36dbac79590e2e8b5aa5/html5/thumbnails/8.jpg)
8
Controller&Action
1つの Contorllerに複数 Actionメソッドを定義@Action
public class TodoController extends Controller { ...
public String show() { ...
return "show.jsp";}public String edit() {
...return "edit.jsp";
}public String confirm() {
...return "confirm.jsp";
}public String save() {
...return "@list";
}}
Controllerreturn “show.jsp”show.jspにフォワード
return “@list”listにリダイレクト
return “/common/error.jsp”/common/error.jspにフォワード
return “@/login/logout”/login/logoutにリダイレクト
![Page 9: Cubby 2006-08-23](https://reader036.vdocuments.pub/reader036/viewer/2022082700/549a36dbac79590e2e8b5aa5/html5/thumbnails/9.jpg)
9
Controller&Action
メタ情報はアノテーションで(ちょっとだけ)@Action
@Form("loginDto")public class LoginController extends Controller {
public static TodoLogic todoLogic = new MockTodoLogic();@Sessionpublic User user;public LoginDto loginDto = new LoginDto();public String login() {
return "login.jsp";}@Validation(errorPage="login.jsp")public String login_process() {
if(todoLogic.login(loginDto)) {user = new User(1, "agata");return "@/todo/list";
} else {errors.add("ユーザ IDかパスワードが違います。 ");return "login.jsp";
}}public String logout() {
user = null;return "@login";
}}
Controller@Actionpublicメソッドをアクションメソッドとみなす(メソッド単位でも設定可能)
@Form(プロパティ名 )パラメータの自動バインディング対象を指定(メソッド単位でも設定可能)
@Validation(errorPage="エラー時の遷移先 ")アクションの実行前にバリデーションを実行
@Sessionセッションスコープの変数として、自動バインディング(その他 publicなフィールドはリクエストスコープ)
![Page 10: Cubby 2006-08-23](https://reader036.vdocuments.pub/reader036/viewer/2022082700/549a36dbac79590e2e8b5aa5/html5/thumbnails/10.jpg)
10
Validation
コードで入力検証を記述
public class Todo implements Validatable {
public static Validators VALIDATORS = new Validators();static {
VALIDATORS.add("text", new Required(), new MaxLength(10));VALIDATORS.add("memo", new Required(), new MaxLength(100));VALIDATORS.add("typeId", new Required());VALIDATORS.add("limitDate", new DateFormat());
}
public Validators getValidators() {return VALIDATORS;
}...
}
Model
![Page 11: Cubby 2006-08-23](https://reader036.vdocuments.pub/reader036/viewer/2022082700/549a36dbac79590e2e8b5aa5/html5/thumbnails/11.jpg)
11
その他の機能
URI自動マッピング (Plugin化 )
- Rails風
- /todo/list→TodoController#list
- /todo/confirm→TodoController#confirm
- /agata/todo/1→TodoController#show?id=1
HTMLプレビュー
- JSPでもブラウザによるプレビューが(ある程度)できます!
@ ActionFilter WebWork2 & Rails風
![Page 12: Cubby 2006-08-23](https://reader036.vdocuments.pub/reader036/viewer/2022082700/549a36dbac79590e2e8b5aa5/html5/thumbnails/12.jpg)
12
ロードマップ 2006年 11 月 Ver0.9
2006年 12 月 Ver1.0-RC
- リファクタリング
- ドキュメントの整備
2007年 1 月 Ver1.0
- サンプルの整備
- JavaDocコメント
一緒に開発してくれる方、募集中です !!
仕様に対するご意見も、お待ちしております。