2

私は、GWT MVP フレームワーク + GWT Editors フレームワークを使用していくつかの小さなプロジェクトに取り組んできました。次のように宣言されたフィールドを持つ Views インターフェイスがあります。

 @Path("field")
 IsEditor<ValueBoxEditor<Long>> getField();

ビューの実装は次のようになります。

@UiField
   IsEditor<ValueBoxEditor<Long>> field;
public IsEditor<ValueBoxEditor<Long>> getField(){
   return field;
}

私のアクティビティには、対応するビューへの参照があり、(アクティビティで)次のようなことをしなければならない場合:

view.getField.setEnable(true);

にキャストする必要があります

((ValueBoxBase<Long>)view.getField()).setEnable(true);

その後、このユニットをテストすることはできません。私のテストでは、結果としてMock(IsEditor<ValueBoxEditor<Long>>)を返すように View の動作を定義しているためです。view.getFiled()

java.lang.ClassCastException: com.google.gwt.editor.client.IsEditor$
$EnhancerByMockitoWithCGLIB$$e8c00c36 cannot be cast to
com.google.gwt.user.client.ui.ValueBoxBase

キャストを行わずにActivityからViewsコンポーネントのメソッドを呼び出すベストプラクティスは何ですか?

4

2 に答える 2

0

ValueBoxBaseではなくHasEnabledにキャストします。

于 2011-04-15T08:38:22.433 に答える
0

ValueBoxEditor アダプタ メソッド "of" を使用する必要があります。

@UiField ValueBoxBase<Long> field;

public ValueBoxEditor<Long> getField(){
   return ValueBoxEditor.of(field);
}
于 2011-07-12T21:13:02.403 に答える