RequestFactory / AutoBean with non-bean value type

71 views
Skip to first unread message

Eric Sirianni

unread,
Sep 14, 2011, 11:32:41 AM9/14/11
to Google Web Toolkit
I would like to use a value type for a bean property in an EntityProxy
that is not natively supported by RequestFactory. In other words, a
java type not in com.google.web.bindery.autobean.shared.ValueCodex
(Enum, BigInteger, BigDecimal, Date, etc.).

http://code.google.com/webtoolkit/doc/latest/DevGuideRequestFactory.html#transportable

The specific use case I have is using Joda-time types (Duration,
Instant, etc.). ValueProxy won't work for these as they do not
conform to JavaBean conventions.

Is this possible? It doesn't appear to be given the current factoring
of the code.

What would be the best workaround? I toyed with the idea of declaring
these properties as Strings in my EntityProxy interface and then
converting them in a crosscutting manner using ServiceLayerDecorator.

i.e.
Object getProperty(Object domainObject, String property) {
Object value = super.getProperty(domainObject, property);
if (value instanceof JodaDuration) {
// ... convert to String
return ...;
} else {
return value;
}
}

In this way the domain objects would use the native Joda type but the
EntityProxy objects would talk in terms of Strings.

Would this work? Any better ideas?

Thanks,
Eric

Thomas Broyer

unread,
Sep 15, 2011, 6:31:37 AM9/15/11
to google-we...@googlegroups.com
I don't think ServiceLayerDecorator would work (interface won't validate against domain object; you could use @SkipInterfaceValidation but that actually wouldn't help, at least with GWT 2.4.0: see my comments on http://code.google.com/p/google-web-toolkit/source/detail?r=10542).

How about adding getters and setters to your domain object that do the conversion between JodaTime types and strings or numbers?

I.e.
public final String getDurationString() {
   return getDuration().toString();
}
public final void setDurationString(String s) {
   setDuration(Duration.parse(s));
}

Not ideal but assured to work.

Ideally of course, ValueCodex would be pluggable. If you have an idea how to refactor it so anyone could plug his "codecs", that'd be awesome ;-)

Eric Sirianni

unread,
Sep 15, 2011, 3:01:24 PM9/15/11
to Google Web Toolkit
Thanks Thomas - that was going to be my workaround, but we have a
fairly rich domain model and use Joda types extensively. Providing
String-based wrapper properties on each entity class is going to be a
bit of a pain. This is why I'd been looking for a more centralized
approach.

I'm not too familiar with AutoBean, but I would think something could
be done here. Are you guys accepting patches :)?

On Sep 15, 6:31 am, Thomas Broyer <t.bro...@gmail.com> wrote:
> I don't think ServiceLayerDecorator would work (interface won't validate
> against domain object; you could use @SkipInterfaceValidation but that
> actually wouldn't help, at least with GWT 2.4.0: see my comments onhttp://code.google.com/p/google-web-toolkit/source/detail?r=10542).

salk31

unread,
Jan 3, 2013, 9:53:12 AM1/3/13
to google-we...@googlegroups.com
For what it is worth we have done the ServiceLayerDecorator and @SkipInterfaceValidation approach and it seems OK (keeps domain code cleaner at least) with GWT 2.5.
Reply all
Reply to author
Forward
0 new messages