Search code examples
gwtgetter-setterrequestfactory

RequestFactory: read only properties on domain object/proxies?


I have Document entity having read-only (from client perspective) property modificationAuthor (I want it to be modified only on server side which is aware of currently logged user). Document entity has has no setters for modificationAuthor property neither in proxy nor in domain object.

The problem is that it's not a simple property but other entity (User) so I need to add modificationAuthor to the paths when I invoke requestFactory.find(id).with(paths).fire() to get Document instance. (so that modificationAuthor is not null when I want to read it from Document).

But after adding it to paths and trying to persist Document object I'm getting exception: Could not locate setter for property modificationAuthor.... It seems that RF requires setters even for properties that are designed to be read-only.

Is there currently any way to avoid adding setters to such properties and be able to read it and persist parent object?


Solution

  • This is a side-effect of issue 5952, which will (should) be fixed in GWT 2.5, to be released in a month or so: RF erroneously thinks the modificationAuthor property has been modified (because it fails at comparing the User entity with itself), so it sends an operation to the server for that property, and the server then tries to set the property value to the given entity (which happens to be the one that's already there).

    In the mean time, I'm afraid you'll have to add a dummy setter (it does not need to actually assign the property value) to your Document domain object.