Andrey Agibalov
Andrey Agibalov

Reputation: 7694

GWT RequestFactory - adding custom methods to proxy classes?

Is is possible to add a method to GWT RequestFactory's proxy class? Let's say I have this:

@ProxyFor(value = MyEntity.class)
interface MyEntityProxy extends EntityProxy {
  String getData(); // got it on server side
}

GetData() is backed at server side, that's fine. What if I'd like to add a method like this:

@ProxyFor(value = MyEntity.class)
interface MyEntityProxy extends EntityProxy {
  String getData(); // got it on server side
  String getDataAndAppendQwerty(); // want this one on client side
}

I want to manually implement getDataAndAppendQwerty(). It's 100% client-side code and the question is just where should I put the implementation.

Upvotes: 2

Views: 704

Answers (2)

Thomas Broyer
Thomas Broyer

Reputation: 64541

The answer would be AutoBean categories, but they're not (yet) surfaced in RequestFactory.

Upvotes: 3

pillingworth
pillingworth

Reputation: 3238

I don't know of an easy way. You could use a wrapper and delegate

public class MyEntityProxyExt implements MyEntityProxy {

  private final MyEntityProxy proxy;

  public MyEntityProxyExt(MyEntityProxy proxy) {
      this.proxy = proxy;
  }

  @Override
  public String getData() {

      return proxy.getData();
  }

  public Object getDataAndAppendQwerty() {

      return proxy.getData() + "qwerty";
  }
}

but you'd have to manually wrap all your proxy objects on the client when you get them back from the server.

Upvotes: 0

Related Questions