With RequestFactory where do utility methods etc live

39 views
Skip to first unread message

salk31

unread,
Jan 26, 2012, 8:36:31 AM1/26/12
to Google Web Toolkit
Where can I put code that works on the entity that I can use in the
server and the client?

e.g. Person and PersonProxy with getSalutation, getFirstName,
getLastName and I want getFullName to work on client and server...
Where should this code live?

The only thing I can think of is to have a new interface PersonFoo
with the getters in that Person and PersonProxy implement/extends.
Then I can have something nasty like
PersonFooImpl.getFullName(PersonFoo p).

I believe you can get the PersonProxy on the server too but I think my
boss would balk at the server code being "contaminated" like this.

No support for Person and PersonProxy getFullName with implementation
on the client? e.g. @IPromiseYouCanCompileThisForClient getFullName()
in the proxy interface?

Cheers

Sam

Thomas Broyer

unread,
Jan 26, 2012, 9:06:04 AM1/26/12
to google-we...@googlegroups.com


On Thursday, January 26, 2012 2:36:31 PM UTC+1, salk31 wrote:
Where can I put code that works on the entity that I can use in the
server and the client?

e.g. Person and PersonProxy with getSalutation, getFirstName,
getLastName and I want getFullName to work on client and server...
Where should this code live?

The only thing I can think of is to have a new interface PersonFoo
with the getters in that Person and PersonProxy implement/extends.
Then I can have something nasty like
PersonFooImpl.getFullName(PersonFoo p).

That should work.
 
I believe you can get the PersonProxy on the server too but I think my
boss would balk at the server code being "contaminated" like this.

Plus, you'd have to create a PersonProxy instance wrapping your Person object.

No support for Person and PersonProxy getFullName with implementation
on the client? e.g. @IPromiseYouCanCompileThisForClient getFullName()
in the proxy interface?

No. 

salk31

unread,
Jun 19, 2012, 8:07:44 AM6/19/12
to google-we...@googlegroups.com
We are trying another approach at the moment. We are generating source by doing some simple transformation of the model source we want to use in the browser. At the moment it is just regexp hack but we have had some success with javaparser ( http://code.google.com/p/javaparser/) although the project seems dead.

So it doesn't do much more than change the package name and change Foo into FooProxy (if we found a ProxyFor annotation)... 

So we don't need the extra layer of interfaces but the code to be shared needs to be self contained (not part of the entity class).

Anybody using a better solution?

If not any suggestions for code that can parse a level of Java the same (or better) than GWT AND then serialise that back into Java source (so IDE etc can look at the generated code)? The GWT parser would be great but no code to take the AST tree and produce Java source? The Eclipse code can do both but seems very hard to untangle from the workspace etc... 

Cheers

Sam
Reply all
Reply to author
Forward
0 new messages