henriks
henriks

Reputation: 131

EntityProxies with immutable ValueProxy properties -> "could not locate setter"

I'm trying to wrap my mind around RequestFactory, but I'm having some problems. I have an entityproxy that has a property which is a valueproxy of an immutable type (joda-time LocalDate), and I'm having problems using this entityproxy in any calls to the server.

I've made the property read-only by only including a getter for the property in the entityproxy, and only including getters for the primitive properties in the valueproxy.

However, as far as I can tell, If I use an entityproxy as an argument in a call to a service method, any referenced valueproxy is automatically marked as edited and all its properties are included in the delta?

This in turn causes ReflectiveServiceLayer to throw an exception about a missing setter on LocalDate.

I've been toying with the idea of implementing a ServiceLayerDecorator which overrides "setProperty" to get around this, but I'm not sure if that's a good solution. Is there any "proper" way to fix this? Ideally, I'd like AbstractRequestContext not to include immutable properties in calls to the server.

I'm using GWT 2.3

edit: I created a workaround like this, but I'm still unsure of whether this is the correct approach:

public class ImmutablePropertyFixServiceLayer extends ServiceLayerDecorator {
    @Override
    public void setProperty(Object domainObject, String property, Class<?> expectedType, Object value) {
        Method setter = getTop().getSetter(domainObject.getClass(), property);
        if (setter != null) {
            super.setProperty(domainObject, property, expectedType, value);
        } else {
            //System.out.println(domainObject.getClass().getName() + "." + property + " doesn't have a setter");
        }
    }
}

Upvotes: 0

Views: 656

Answers (1)

Colin Alworth
Colin Alworth

Reputation: 18346

EntityProxy objects have some way they can be easily retreived on the server, so when sending an object back to the server, just the ID is required. ValueProxy objects on the other hand can only be sent as the combination of all of their sub-values. When sending an immutable value back to the server, the server code doesn't know how to turn a proxy back into a server-side value.

I'd be concerned with your solution that you might not be correctly getting the same date on the server as was sent from the client.

Upvotes: 1

Related Questions