• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to use the server-side ?

 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to learn gwt by myself
I learned successfully the client-side, but I do not know how to use the server-side.

I tried with this tutorial
http://code.google.com/intl/es-ES/webtoolkit/doc/1.6/DevGuideServerCommunication.html

But I do not know why should I use this:






Should I use the "request.getParameters()" ?

If i have a class called Person with the attributes name,and phone, how should I use this attributes in a the gwt client-side ??

Thanks
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are referring to 1.6. I would recommend upgrading to the latest version which is 2.0
http://code.google.com/intl/es-ES/webtoolkit/doc/latest/tutorial/gettingstarted.html

Which part are you facing a problem? Making a call? POJOs?
As the document you are referring to explains, you need to create the client proxy and invoke the methods on this proxy just like you would do in a standard Java style.
If you can tell us exactly which part do you not understand, we can help you better.
 
matias casal
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What i can not understand is

from http://code.google.com/intl/es-ES/webtoolkit/doc/latest/DevGuideServerCommunication.html

where

It is safe to cache the instantiated service proxy to avoid creating it for subsequent calls. For example, you can instantiate the service proxy in the module's onModuleLoad() method and save the resulting instance as a class member.



How should I instantiate the proxy?
How should I "create the client proxy" ?

Thanks!


 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From the link you provided, this is how it is done

Notice how myEmailService is used in the sendEmail method.
 
matias casal
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you
I was able to solve it.

Now i Have a new problem.

I created a class on the server package



But when I am going to google-compile the project, this errors appear

[ERROR] Errors in 'file:/C:/Documents%20and%20Settings/mcasal/Mis%20documentos/proyectos-eclipse/probando3/src/testing3/client/Hello.java'
[ERROR] Line 77: No source code is available for type testing3.server.Usuario; did you forget to inherit a required module?
[ERROR] Errors in 'file:/C:/Documents%20and%20Settings/mcasal/Mis%20documentos/proyectos-eclipse/probando3/src/testing3/client/MyService.java'
[ERROR] Line 13: No source code is available for type testing3.server.Usuario; did you forget to inherit a required module?
[ERROR] Errors in 'file:/C:/Documents%20and%20Settings/mcasal/Mis%20documentos/proyectos-eclipse/probando3/src/testing3/client/MyServiceAsync.java'
[ERROR] Line 9: No source code is available for type testing3.server.Usuario; did you forget to inherit a required module?


I imported the Usuario class in the entry point class

Any suggestion?
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since your Usuario class implements Serializable I presume that is your POJO which you are going to pass between the client/server through your proxy. Such POJOs should be packaged under client and not server. Refactor it to be packged under testing3/client
Also, your POJO should have a default constructor (no args and empty) In your class you will need to create one.


I imported the Usuario class in the entry point class


Take this you. You don't need it.
 
matias casal
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh nice, it works.
But if want to use a class from the server, how should I use it?

Thanks
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Classes from the server side can be used only on the server side.
Classes from the client side can be used in both. The reason for this is that since GWT translates your java code into java script (remember GWT is all about UI) it needs the source code to do this translation and it is geared to pick up only the client and its children for this translation.
So your server side code is never translated to JS and you get the error.

As a rule of the thumb, keep your UI components and POJOs under client
Everything else can go under server. If you need to make use of some server side class (which does not logically belong to the client side) you can always make a server call via the proxy
 
matias casal
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

If you need to make use of some server side class (which does not logically belong to the client side) you can always make a server call via the proxy


I undestand this, but how to make a server call via the proxy?
I used to think that using my class function getName() here, on the client-side ( in the entry point) was right



But i am wrong.

Then, how should I use the the proxy
Thanks for answering!
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is MyClass? Is it a POJO? If yes, then your code is correct.
What happens when you execute that code? What error do you get?
 
matias casal
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is that if myclass is in the server package,gwt does not compile.
If the class is in the client package everything go alright.

I would like to know how to use classes form de server package

This is the error log

Charles is my java class in the server package,
Usuario is my java class in the client package,
Hello is my entry point class

Compiling module testing3.Probando3
Validating newly compiled units
[ERROR] Errors in 'file:/C:/Documents%20and%20Settings/mcasal/Mis%20documentos/proyectos-eclipse/probando3/src/testing3/client/Usuario.java'
[ERROR] Line 4: The import testing3.server.Charles cannot be resolved
[ERROR] Line 33: Charles cannot be resolved to a type
[ERROR] Line 33: Charles cannot be resolved to a type
[ERROR] Line 34: Charles cannot be resolved to a type
Finding entry point classes
[ERROR] Unable to find type 'testing3.client.Hello'
[ERROR] Hint: Previous compiler errors may have made this type unavailable
[ERROR] Hint: Check the inheritance chain from your module; it may not be inheriting a required module or a module may not be adding its source path entries properly


 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looks like compilation problems to me. Nothing to do with GWT.
Are you using Eclipse? If yes, Ctrl+1 on the underlined red part of the code offers some suggestions to fix the issue.
 
Any sufficiently advanced technology will be used as a cat toy. And this tiny ad contains a very small cat:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic