1

I just joined a GWT project.

Our goal now is to create more pages with login.

I would like to add these pages as simple HTML and use the existing GWT backend.

Is this possible?

When I look at the network in the current login page, I see GWT uses a long string concatenated with vertical bars, something like :

7|0|11|http://15.165.128.219:8099/welcome/|B080515AD1EBC13C065F38E72385F941|com.company.AdminService|login|com.company.LoginDetails/94248548|java.util.HashSet/3273092938|java.lang.String/2004016611|myusername|mypassword|1|2|3|4|1|5|5|P__________|6|1|7|8|6|1|7|9|10|11|

And I know JQuery Ajax

$.ajax( { username : "username" , password : "password" }

The GWT response looks like:

//OK['C',[],0,7]

How do I go about bridging the two technologies? What is the correct way to dispatch JQuery Ajax requests and reply using GWT?

guy mograbi
  • 27,391
  • 16
  • 83
  • 122

4 Answers4

3

The use of GWT is to use it as a front-end technology. If you want to remove that functionality then you might not need GWT at all and use a back-end technology.

Vjeetje
  • 5,314
  • 5
  • 35
  • 57
  • I still want the front-end as well as the backend. I just want to reuse the backend. Lets assume a 3rd-party needs to integrate with me. And that 3rd-party uses only JavaScript/HTML.. how would we do it. – guy mograbi Feb 17 '13 at 14:39
2

GWT has three "layers" client, shared and server.

On server side you can use what ever is suitable for Java and database.

GWT has its own mechanism for remote procedure calls between the browser and the server.

This works a lot like vanilla Java RMI - define interfaces and implementations for your server functions, and code will be generated to allow your client code to call them as if they were simple local methods.

This blows away all the work of defining XML or JSON data formats for requests and responses. Just code the function for the server, call the function (still in Java) from the client code, and all of the marshalling, unmarshalling, network communication, etc. is done for you.

So Without client you can't use the RPC functionality alone and its not a good pratcise to use like that .

My suggetion is to go for Pure `AJAX`.
Suresh Atta
  • 120,458
  • 37
  • 198
  • 307
  • But you say the client side supports marshalling/unmarshalling.. why can't I reuse that somehow ? – guy mograbi Feb 17 '13 at 14:41
  • You can achieve marshalling/unmarshalling somehow ,but what i am saying is instead of getting that somehow,i am suggesting pure AJAX . – Suresh Atta Feb 17 '13 at 17:37
2

The correct way to dispatch ajax requests via javascript to a GWT RPC call is to make the call into a javascript api. Gwt has a library that makes this fairly easy - https://code.google.com/p/gwt-exporter/

it allows you to annotate methods in GWT's java code (say, a class containing a method that calls some GWT RPC), and make it available to javascript under a nice name.

e.g.,

  package com.example;
  @Export
  public static class YourClass implements Exportable {
    private YourServiceAsync service = (YourServiceAsync) Gwt.create(YourService.class);
    public void foo() {
      //you can make RPC calls here via the normal GWT way
      service.doService("foo", new YourAsyncCallback()); 
    }
    public static String bar(){
      return "bar";
    }
  }

then in javascript, you can make calls to those methods

   // create an instance of YourClass 
   var a = new com.example.YourClass ()
   // call an instance method
   a.foo();
   // call a static method
   com.example.YourClass .bar();

There are more advanced uses (like passing in closures in javascript) - check the doco/wiki on that project.

Chii
  • 14,540
  • 3
  • 37
  • 44
  • I've tried this. This works great for models. How about services? can you give an example to a service that can be exported? – guy mograbi Jul 03 '13 at 08:44
1

By the time you wrote your own code to make requests to, and parse the response from GWT-RPC you'd have rewritten a fair chunk of GWT.

Your best bet is either using GWT on the client side to handle the server communication (and then perhaps passing off the results to jQuery) or to write something like a servlet on the server side that is an alternate interface to the GWT-RPC calls.

However, if you insist on going down this road the place to start is this question: GWT RPC data format

the selected answer links a source for a basic overview of the format. For the full details though there is no choice but to dig into the source. The protocol isn't fully documented anywhere else.

Community
  • 1
  • 1