scenic3 0.1.0 リリース

slim3を薄くラップして、t2 framework のようなPageクラスでコントローラを記述できる拡張ライブラリscenic3をリリースしました。まだ、トライアル版に近くテストなどが十分ではありませんが、slim3の「1コントローラ=1アクションクラス」がしっくり来ない人は試してみてください。
プロジェクトサイト: http://code.google.com/p/scenic3/
ドキュメント: http://sites.google.com/site/aboutscenic3/

使い方はドキュメントにある程度は書いてありますが、slim3の設定ができてれば簡単です。

  1. WEB-INF/lib に scenic3-0.1.0.jar を追加
  2. WEB-INF/web.xml のFrontControllerを org.slim3.controller.ScenicFrontController に変更
  3. プロジェクトのAnnotation ProcessorのFactory Pathに上記 scenic3-0.1.0.jar を追加
  4. 上記Annotation ProcessorのOptionにslim3.rootPackage を追加(値はweb.xmlと同じパッケージ)
  5. AppUrlsを作成する(ここを参照)

後はこんな感じにPageクラスを記述できます。

package scenic3sample.page;

import java.util.List;

import org.slim3.controller.Navigation;
import org.slim3.util.RequestMap;

import scenic3.ScenicPage;
import scenic3.annotation.ActionPath;
import scenic3.annotation.Default;
import scenic3.annotation.Page;
import scenic3sample.model.Tweet;
import scenic3sample.service.TwitterService;

@Page("/twitter")
public class TwitterPage extends ScenicPage {

    private TwitterService service = new TwitterService();
    
    @ActionPath("tweet")
    public Navigation tweet() {
        service.tweet(new RequestMap(request));
        return redirect(basePath);        
    }
    
    @Default
    public Navigation index() {
        List<Tweet> tweetList = service.getTweetList();
        requestScope("tweetList", tweetList);
        return forward("/twitter/index.jsp");
    }
    
}

すると、APTにより2つのコントローラとマッチングクラスが生成され、通常のslim3と同じように振る舞います