how to use a server class in client code

15 views
Skip to first unread message

Sanjith Chungath

unread,
Nov 8, 2009, 1:30:25 PM11/8/09
to Google Web Toolkit
Greetings to all,
       I have defined a class in the server and want to get a list of objects (of that class) as return parameter of an async call. But while compile I got  following error "No source code is available for type com.abc.pqr.data.XXX; did you forget to inherit a required module?". I know that it is because GWT dont know the java script code for coresponding class. What is the general practice to use a object of class in server side at client code, serialize it? or any other better way.

-Sanjith.

Dalla

unread,
Nov 8, 2009, 3:53:56 PM11/8/09
to Google Web Toolkit
I guess it depends on what your server side object looks like.

I´ve been using a mapping framework called Dozer in a couple of
projects where
I needed to use EJB-classes on the client side. What you do in that
case is basically create a
POJO that is a mirror of your EJB, but without all the annotations.
The resulting object is something that the GWT-compiler
can understand. So on the server side you do the mapping, EJB -> POJO,
and then transfer the POJO to the client side.
If you need to persist some changes to the EJB, you just send your
POJO back to the server side, and reverse the mapping, that is POJO ->
EJB.

However I´m not sure this is relevant info in your case.
Maybe if you post your server side object we can help better.

rjcarr

unread,
Nov 8, 2009, 10:35:06 PM11/8/09
to Google Web Toolkit
Hi Sanjith-

I don't completely follow your question but any shared code between
the client and the server has to reside in the client package (by
default). This is because GWT can only see code in the modules you
have defined and the server package isn't a GWT module (again, by
default).

Hope this helps!

DaveS

unread,
Nov 9, 2009, 6:01:45 AM11/9/09
to Google Web Toolkit
That's how we did it originally, but then we created a separate GWT
project (well, actually it's just a JAR project) that defines all our
types that are common over the RPC interfaces. We reference that
project in both the server and client projects, and the JAR gets
pulled into the client side and GWT happily generates JS code from it.
We now also use it for some 'shared' client-side classes as well so
it's effectively just a library project.

DaveS.

sathya

unread,
Nov 9, 2009, 6:40:44 AM11/9/09
to Google Web Toolkit
Hi,
You can serialize classes only defined in client side(not server
side).Class you defined on server side should be moved to client side
to serialize.
> > > -Sanjith.- Hide quoted text -
>
> - Show quoted text -

Sanjith Chungath

unread,
Nov 9, 2009, 12:39:02 PM11/9/09
to google-we...@googlegroups.com
Thanks to all for your suggestions.

As my application needs to be deployed in google app engine, I doubt whether I can move those classes from server to client. I use JDO to persist objects to the GAE data store. The class is a simple class and I have mentioned it below,

@PersistenceCapable(identityType = IdentityType.DATASTORE)
public class PhotoSetStore {
@PrimaryKey
@Persistent
private String setid;

@Persistent
private String title;

@Persistent
private String description;

@Persistent
private String primaryPhotoURL;

public PhotoSetStore(String id, String title, String descString,
String photoURL) {
setSetID(id);
setTitle(title);
setDescrption(descString);
setPrimaryPhotoURL(photoURL);
}
}

Dave, it looks simple approach to have a (java) project to have common classes defined. I need few clarifications, do you have seperate projects for GWT client code and server code? If not, how did you added the common .jar file to the client code? 

Also, I didnt quiet get how the common .jar file is different from the class existing in a server package of same GWt project!

-Sanjith

Dalla

unread,
Nov 9, 2009, 1:40:44 PM11/9/09
to Google Web Toolkit
I´m not sure you can solve this particular problem the way DaveS
suggested, not without modifying the class anyway.
Even if you created a separate .jar and referenced that from your
client project, the GWT compiler wouldn´t understand the annotations.

My problem was similar to yours, and would be solved by creating a new
even simpler class like this:

Public class PhotoSetStoreDTO {

private String setid;
private String title;
private String description;

private String primaryPhotoURL;
public PhotoSetStore(String id, String title, String descString,
String photoURL) {
setSetID(id);
setTitle(title);
setDescrption(descString);
setPrimaryPhotoURL(photoURL);

}
}

Then use Dozer or a similar mapping framework to do the mapping
between server side and client side objects.
I haven´t been working with GAE at all to be honest, so there might be
a better approach.

Dominik Steiner

unread,
Nov 10, 2009, 12:42:58 PM11/10/09
to Google Web Toolkit
Sanjith,

I'm using GWT on GAE and I also have my data model classes with JDO
annotations. I have those classes reside under client/domain and GWT
2.0 handles/ignores those JDO related annotations well and i don't
have to use Dozer or another framework in order to be able to use
those classes on the client.

If you need more help, please let me know.

HTH

Dominik

Sanjith Chungath

unread,
Nov 11, 2009, 12:32:34 PM11/11/09
to google-we...@googlegroups.com
@Dalla: Thanks again for those steps. As i am not familiar with those tools am finding a bit difficult to handle it.

@Dominik:  Thanks a lot for that information. It will save a lot of life for me. So is it enough to move my current class definitions from the server to the client/domain package and use them at both server and client code?

-Sanjith

Dominik Steiner

unread,
Nov 11, 2009, 2:58:55 PM11/11/09
to google-we...@googlegroups.com
Sanjith,

you can move the model classes to anywhere under the client folder,
the client/domain example is just what i use here with me. And then
the server will reuse those classes on server side where he will read
the jdo annotations.

Let me know if it works for you

Dominik

Ray

unread,
Nov 16, 2009, 5:59:33 AM11/16/09
to Google Web Toolkit
Hello,

I have my DTO (domain model) classes - which are serializeable POJOs
without annotations - inside jar files on the server, as i want to use
them not only in GWT applications.

Is there no other solution of reusing them on my GWT-client-side
without copying the source
code to the client. Because in the case of changes I don't want to
change the DTO classes at two different places (GWT-Client+Server-
api.jar)

Thanks,
Ray


On 11 Nov., 20:58, Dominik Steiner <dominik.j.stei...@googlemail.com>
wrote:

Ray

unread,
Nov 16, 2009, 7:01:32 AM11/16/09
to Google Web Toolkit
Hello,

I have my model classes inside an library on the server-side which I
want user for different applications (not only GWT)

Copying my domain classes to the client side of the GWT-Client-App
doesn't seem to be very convienient, as I have to maintain the same
code in two different locations.

Is there no way to include the library and GWT creates the client-side
java-script whith the model automatically?

Thanks
Ray


On 11 Nov., 20:58, Dominik Steiner <dominik.j.stei...@googlemail.com>
wrote:

Brian

unread,
Nov 17, 2009, 10:11:44 AM11/17/09
to Google Web Toolkit
I've experimented with creating a code generator to use reflection to
generate client side DTOs along with utility classes to convert
between the two. This way, I'm only maintaining the classes in one
place and the rules that the actual server side classes have to follow
are reduced from what GWT-RPC requires. I'm not completely sold on
this idea, but it's working for me for now.

The code generator is very rough right now and in no shape for
sharing, but I may spend some time cleaning it ip eventually. Would
anyone else be interested in a tool like that?

-Brian
Reply all
Reply to author
Forward
0 new messages