Fight the Future

Java言語とJVM、そしてJavaエコシステム全般にまつわること

Introducing Apache Wicketの超意訳(3)

http://www.theserverside.com/tt/articles/article.tss?l=IntroducingApacheWicket

Models(モデル)

Components aren't very interesting unless they have domain-specific data to display and manipulate.
However, just passing a domain object to a component isn't feasible
unless the component knows how to interrogate every domain object in your application.
Instead, we need an abstraction between the component and the domain object.
This is where models come in.

コンポーネントはドメイン特有のデータを表示したり操作したりしない限りそれほど興味深いものではありません。
しかしながら、コンポーネントがアプリケーションにおいてあらゆるドメインオブジェクトを問い合わせる方法を知らない限り、
コンポーネントへドメインオブジェクトを渡すことだけは実現できません。
それどころか、コンポーネントとドメインオブジェクトの間に抽象化が必要です。
これがモデルが出現する場所です。

The base of Wicket's model hierarchy starts with IDetachable and IModel:

Wicketのモデルの階層の基礎はIDetachableとIModelから始まります。

The IDetachable primarily exists to support clustering, as well as detachable models, which we'll explore later on.
Most of the time you don't need to be concerned with this interface.

そもそもIDetachableは、分離可能なモデルのみならず、クラスタリングもサポートするために存在します。これについては後述します。
ほとんどの場合、このインタフェースに関心を持つ必要はないでしょう。

Models wrap objects, providing data to components using the model.
The object contained by the model is called the model object.
The simplest model example is

モデルはオブジェクトをラップし、モデルを使用するコンポーネントへデータを提供します。
モデルが含むオブジェクトはモデルオブジェクトと呼ばれます。
最も簡単なモデルの例は次のようなものです。

IModel nameModel = new Model("Chauncey Billups");

In the above example we create a Model object, which implements the IModel interface, and pass it a string.
The org.apache.wicket.model.Model class takes any object implementing java.io.Serializable, so a String works.
To use the Model, simply pass it to a component:

上の例でモデルのオブジェクトを生成しました。このオブジェクトはIModelを実装し、それに文字列を渡します。
org.apache.wicket.model.Modelはjava.io.Serializableを実装するあらゆるオブジェクトを引数に取ります。したがってStringは動作します。
モデルを利用するために、モデルを単純にコンポーネントに渡します。

Label playerName = new Label("playerName", nameModel);

When the component's markup is generated, the component calls IModel's getObject() method to get the data to display.

コンポーネントマークアップが生成されるとき、コンポーネントはIModelのgetObject()メソッドを呼び出してデータを表示します。