6

My GWT app has ten different kinds of entities. Right now I use plain old DTOs and transport them over GWT-RPC. This works well for cases like startup - I can pack them all into a single request.

I'm looking at switching to RequestFactory because there are many times throughout the lifetime of the app (30 minutes, on average) when I just have to update one type of entity, and the unifying/bandwidth-saving features of RequestFactory are appealing. BUT: I don't see a way to download all of my initialization data in a single request when the app loads. I don't want to have to make ten requests to fetch all of the init data for my ten entity types.

Is there a way to make a GeneralRequestContext, or something? I'd even be happy with a solution like:

public interface InitDataProxy extends EntityProxy
{
    public UserProxy getInitUsers();
    public OrganizationProxy getInitOrganizations();
    ...
}

public interface GeneralRequestContext extends RequestContext
{
    Request<InitDataProxy> getInitData();
}

But this won't work because I don't want to have to actually back InitDataProxy with anything, I just want to use it to combine a bunch of different types of Proxies in a single request.

So: Is there a way to receive multiple, unrelated types of EntityProxy in a single request?

I would also be happy enough making a normal gwt-rpc request to go outside of RequestFactory for this data, but I don't want to have to implement duplicate DTOs to run next to RequestFactory's proxies, and write custom code to copy the DTOs into them!

1 Answer 1

4

The InitDataProxy could extend ValueProxy instead, which doesn't require that the object on the server have any kind of id or version semantics. The domain-side InitData type could be an interface, possibly implemented with an anonymous type.

interface InitData {
  User getUser();
  Organization getOrgatization();
}
class InitService {
  static InitData makeInitData() {
    return new InitData() { ..... };
  }
}

@ProxyFor(InitData.class)
interface InitDataProxy extends ValueProxy {
  UserProxy getUser();
  OrganizationProxy getOrganization();
}
@Service(InitService.class)
interface Init extends RequestContext {
  Request<InitDataProxy> makeInitData();
}
Sign up to request clarification or add additional context in comments.

5 Comments

Ah, great. Thanks - this brings the number of outstanding obstacles between me and using RF down to one, and I feel it crumbling away too! I appreciate your work!
A RequestContext can be seen as a "bag of method invocations" that allows you to batch them in a single HTTP request. This means you don't have to combine your results in a single type; you can call several methods on the RequestContext and only then fire() it to send the method calls to the server as a "batch".
Hey just saw this and will try this with a ValueProxy too soon. But last time I experimented with ValueProxys (don't remember the GWT version though) GWT kept complaining about the class the ValueProxy stands for is missing default constructor and is missing setter methods for the properties. Let's see if this is working in current versions :)
@ThomasBroyer but if you combine several methods in a single RequestContext and then fire(), then how do you give a single Receiver to each of those methods?
There's one Receiver per Request<?> and one global Receiver<Void> for the RequestContext (but that one doesn't receive any value, only a global "succeeded / failed / constraint violations" information)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.