実行例

では実際に、作った派生クラスを使用してみます。
チュートリアル1のログインページのパスワード入力欄を置き換えてみます。

ユーザーID
パスワード

login.html
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<title>ログイン</title>
</head>
<body>
<form action="hello.html">
ユーザーID <input size="20" type="text" name="user_id"><br>
パスワード <input size="20" type="password" name="password" class="custom"><br>
<br>
<input type="image" src="button1.gif"></form>
</body>
</html>

スケルトンを生成する際に、先程作成した Custom クラスを指定します。

java paraselene.mockup.Make -html src -out out -package tutorial1 -other ./ -exclude error.html -grant_tag_provider lib.Custom

-grant_tag_provider には、複数のクラスを指定可能です。 複数のクラスを指定した場合には、指定された順番に各 getGrantTag を呼び出し、どれかが null 以外を返すと、その派生クラスを採用します。 全て null を返した場合は、Paraselene デフォルトのクラスを使用します。

この時の生成される logic/LoginHtml.java には変化はありませんが、view/LoginHtml.java は以下のような変化があります。

lib.CustomSingleTextBox tag30=new lib.CustomSingleTextBox(true); init メソッドで、SingleTextBox の代わりに派生クラスを new するソースに置き換わっています。
public lib.CustomSingleTextBox getPasswordInput() {
  return (lib.CustomSingleTextBox)getTag( "password" );
}
アクセッサとなる、getPasswordInput メソッドは、SingleTextBox の代わりに派生クラスをリターンするソースに置き換わっています。

応用編

最終更新: 2009/10/21
特に明示されていない限り、本Wikiの内容は次のライセンスに従います:CC Attribution 3.0 Unported
文書の先頭へ
SourceForge.JP
2009 © Akira Terasaki.  
Driven by DokuWiki The Apache Software Foundation