5

編集者が編集しているプロキシを取得する方法はありますか?

通常のワークフローは次のとおりです。

 public class Class implments Editor<Proxy>{
  @Path("")
  @UiField AntoherClass subeditor;


  void someMethod(){
   Proxy proxy = request.create(Proxy.class);
   driver.save(proxy);
   driver.edit(proxy,request);
 }
}

同じプロキシのサブエディターを取得した場合

public class AntoherClass implements Editor<Proxy>{
   someMethod(){
   // method to get the editing proxy ?
    }
 } 

はい、作成後にsetProxy()を使用して子エディターにプロキシを設定できることはわかっていますが、編集されたプロキシ以外にHasRequestContextのようなものがあるかどうかを知りたいです。

これは、たとえば非UIオブジェクトでListEditorを使用する場合に役立ちます。

ありがとうございました。

4

3 に答える 3

7

特定のエディターが作業しているオブジェクトへの参照を取得する2つの方法。まず、いくつかの単純なデータと単純なエディター:

public class MyModel {
  //sub properties...

}

public class MyModelEditor implements Editor<MyModel> {
  // subproperty editors...

}

まず、を実装する代わりにEditor、Editorを拡張するが、サブエディターを許可する(サブエディターをLeafValueEditor許可しない)別のインターフェースを選択できます。試してみましょうValueAwareEditor

public class MyModelEditor2 implements ValueAwareEditor<MyModel> {
  // subproperty editors...

  // ValueAwareEditor methods:
  public void setValue(MyModel value) {
    // This will be called automatically with the current value when
    // driver.edit is called.
  }
  public void flush() {
    // If you were going to make any changes, do them here, this is called
    // when the driver flushes.
  }
  public void onPropertyChange(String... paths) {
    // Probably not needed in your case, but allows for some notification
    // when subproperties are changed - mostly used by RequestFactory so far.
  }
  public void setDelegate(EditorDelegate<MyModel> delegate) {
    // grants access to the delegate, so the property change events can 
    // be requested, among other things. Probably not needed either.
  }
}

これには、上記の例のようにさまざまなメソッドを実装する必要がありますが、関心のある主なメソッドはですsetValue。これらを自分で呼び出す必要はありません。ドライバーとそのデリゲートによって呼び出されます。このflushメソッドは、オブジェクトに変更を加える予定がある場合にも使用できます。フラッシュの前にこれらの変更を行うと、予想されるドライバーのライフサイクルの外でオブジェクトを変更することになります。世界の終わりではありませんが、後で驚かれる可能性があります。

2番目:SimpleEditorサブエディターを使用します:

public class MyModelEditor2 implements ValueAwareEditor<MyModel> {
  // subproperty editors...

  // one extra sub-property:
  @Path("")//bound to the MyModel itself
  SimpleEditor self = SimpleEditor.of();

  //...
}

self.getValue()これを使用して、現在の値が何であるかを読み取るために呼び出すことができます。

編集:AnotherEditor実装したものを見ると、GWTクラスのようなものを作成し始めているように見えますが、SimpleEditor他のサブエディターも必要になる場合があります。

同じプロキシのサブエディターを取得した場合

public class AntoherClass implements Editor<Proxy>{
  someMethod(){  
    // method to get the editing proxy ?
  }
}

このサブエディターは、ValueAwareEditor<Proxy>の代わりに実装でき、編集の開始時にEditor<Proxy>そのsetValueメソッドがProxyインスタンスで呼び出されることが保証されます。

于 2012-04-13T18:49:52.530 に答える
2

子エディタークラスでは、別のインターフェイスTakesValueを実装するだけで、setValueメソッドで編集プロキシを取得できます。

ValueAwareEditorも機能しますが、実際には必要のない追加のメソッドがすべてあります。

于 2012-05-12T14:29:27.913 に答える
0

これは私が見つけた唯一の解決策です。これには、ドライバー編集を呼び出す前にコンテキスト編集を呼び出すことが含まれます。次に、後で操作するプロキシがあります。

于 2012-04-13T17:31:14.123 に答える