RequestFactory doesn't populate all fields of

2019-03-03 05:18发布

问题:

Could you please tell me how I can make RequestFactory populate fields of my entity proxy that are entity proxies too ?

Here is parent proxy

@ProxyFor(value = Organization.class, locator = PojoLocator.class)
public interface OrganizationProxy extends EntityProxy
{
    public String getName();
    public void setName(String name);
    public String getAddress();
    public void setAddress(String address);
    public PersonProxy getContactPerson();
    public void setContactPerson(PersonProxy contactPerson);
}

as you can see it contains another proxy as field. Here is how PersonProxy looks like

@ProxyFor(value = Person.class, locator = PojoLocator.class)
public interface PersonProxy extends EntityProxy
{
    public String getName();
    public void setName(String name);
    public String getPhoneNumber();
    public void setPhoneNumber(String phoneNumber);
    public String getEmail();
    public void setEmail(String email);
    public OrganizationProxy getOrganization();
    public void setOrganization(OrganizationProxy organization);
}

In my RequestContext interface I have method Request<OrganizationProxy> findOrganizationById(long id). DAO class that fetches real Organization from datastore sets its contactPerson field but in the client it's always null. In fact RequestFactory never even calls Organization.getContactPerson().

My client call looks like this

createFactory().contextOrder().findOrganizationById(1).fire(new Receiver<OrganizationProxy>()
{
    @Override
    public void onSuccess(OrganizationProxy response)
    {
        if (response == null)
        {
            organizationProxy = orderRequestContext.create(OrganizationProxy.class);
            organizationProxy.setContactPerson(orderRequestContext.create(PersonProxy.class));
        } else
            organizationProxy = orderRequestContext.edit(response);

        // Copy the data in the object into the UI
        driver.edit(organizationProxy);
    }

    @Override
    public void onFailure(ServerFailure error)
    {
        createConfirmationDialogBox(error.getMessage()).center();
    }
});

What am I missing here ? Shall I do something somewhere manually ? Isn't RequestFactory supposed to populate whole graph ?

回答1:

Sorry but I found the answer. I should have RTFM.

When querying the server, RequestFactory does not automatically populate relations in the object graph. To do this, use the with() method on a request and specify the related property name as a String