Validationをテンプレートで定義

直感的に書けるんじゃないかと思って試してみた。

ページ


public class Login extends Page {

public Form form = new Form();

public static RegexField user = new RegexField("user", "ユーザ名?");

private PasswordField passwd = new PasswordField("passwd", "パスワード?");

public Login() {
form.add(user);
form.add(passwd);
form.add(new Submit("login", "ログイン", this, "onLoginClick"));
form.add(new Reset("reset", "リセット"));
}

public boolean onLoginClick() {
// 認証処理 return true;
}

}

テンプレート


#set($user.required = true)
#set($user.maxLength = 8)
#set($user.pattern = "[a-zA-Z]+")
<html>
<head>
<title>Blank</title>
</head>
<body>
$form
</body>
</html>

スクリーンショット


staticが微妙…。いやな臭いがする。